From 1e2fb8f3782118d723e67428d8f31a58685dd114 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 22 Sep 2025 12:26:40 -0400 Subject: [PATCH 1/2] fix: error translation based on explicit string --- src/lib/errors.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/lib/errors.ts b/src/lib/errors.ts index 5b01f086..0dffa813 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,19 @@ export default class IpldExploreError extends Error { * t('NameOfErrorClassThatExtendsIpldExploreError') */ toString (t: TFunction<'translation', 'translation'>): string { - return t(this.name, this.options) + const translationKey = this.translationKey ?? this.name + return t(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' +} From a03b80bf1c7699330acf1328c70e919fdfd7464b Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 22 Sep 2025 12:29:06 -0400 Subject: [PATCH 2/2] fix: this.name doesnt exist on errors anymore --- src/lib/errors.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/errors.ts b/src/lib/errors.ts index 0dffa813..e3211ea2 100644 --- a/src/lib/errors.ts +++ b/src/lib/errors.ts @@ -20,8 +20,7 @@ export default class IpldExploreError extends Error { * t('NameOfErrorClassThatExtendsIpldExploreError') */ toString (t: TFunction<'translation', 'translation'>): string { - const translationKey = this.translationKey ?? this.name - return t(translationKey, this.options) + return t(this.translationKey, this.options) } }