Skip to content

Commit 347d38c

Browse files
authored
fix: error translation based on explicit string (#482)
* fix: error translation based on explicit string * fix: this.name doesnt exist on errors anymore
1 parent 8718cd0 commit 347d38c

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

src/lib/errors.ts

Lines changed: 16 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,18 @@ 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+
return t(this.translationKey, this.options)
2124
}
2225
}
2326

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

0 commit comments

Comments
 (0)