diff --git a/src/lib/errors.ts b/src/lib/errors.ts index 5b01f086..e3211ea2 100644 --- a/src/lib/errors.ts +++ b/src/lib/errors.ts @@ -1,9 +1,12 @@ import { type TFunction } from 'i18next' export default class IpldExploreError extends Error { + // translation key to prevent minification issues + readonly translationKey: string + constructor (private readonly options: Record) { super() - this.name = this.constructor.name + this.translationKey ??= this.constructor.name } /** @@ -17,8 +20,18 @@ export default class IpldExploreError extends Error { * t('NameOfErrorClassThatExtendsIpldExploreError') */ toString (t: TFunction<'translation', 'translation'>): string { - return t(this.name, this.options) + return t(this.translationKey, this.options) } } -export class BlockFetchTimeoutError extends IpldExploreError {} +export class BlockFetchTimeoutError extends IpldExploreError { + readonly translationKey = 'BlockFetchTimeoutError' +} + +export class BlockFetchError extends IpldExploreError { + readonly translationKey = 'BlockFetchError' +} + +export class CidSyntaxError extends IpldExploreError { + readonly translationKey = 'CidSyntaxError' +}