Skip to content

Commit 1e2fb8f

Browse files
committed
fix: error translation based on explicit string
1 parent e673c91 commit 1e2fb8f

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/lib/errors.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { type TFunction } from 'i18next'
22

33
export default class IpldExploreError extends Error {
4+
// translation key to prevent minification issues
5+
readonly translationKey: string
6+
47
constructor (private readonly options: Record<string, string | number>) {
58
super()
6-
this.name = this.constructor.name
9+
this.translationKey ??= this.constructor.name
710
}
811

912
/**
@@ -17,8 +20,19 @@ export default class IpldExploreError extends Error {
1720
* t('NameOfErrorClassThatExtendsIpldExploreError')
1821
*/
1922
toString (t: TFunction<'translation', 'translation'>): string {
20-
return t(this.name, this.options)
23+
const translationKey = this.translationKey ?? this.name
24+
return t(translationKey, this.options)
2125
}
2226
}
2327

24-
export class BlockFetchTimeoutError extends IpldExploreError {}
28+
export class BlockFetchTimeoutError extends IpldExploreError {
29+
readonly translationKey = 'BlockFetchTimeoutError'
30+
}
31+
32+
export class BlockFetchError extends IpldExploreError {
33+
readonly translationKey = 'BlockFetchError'
34+
}
35+
36+
export class CidSyntaxError extends IpldExploreError {
37+
readonly translationKey = 'CidSyntaxError'
38+
}

0 commit comments

Comments
 (0)