Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/lib/errors.ts
Original file line number Diff line number Diff line change
@@ -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<string, string | number>) {
super()
this.name = this.constructor.name
this.translationKey ??= this.constructor.name
}

/**
Expand All @@ -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'
}
Loading