-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy patherrors.ts
More file actions
26 lines (22 loc) · 829 Bytes
/
errors.ts
File metadata and controls
26 lines (22 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { type TFunction } from 'i18next'
export default class IpldExploreError extends Error {
constructor (private readonly options: Record<string, string | number>) {
super()
this.name = this.constructor.name
}
/**
* See IpldExploreError for usage.
* You must pass a t function that is registered with namespace 'explore' and keyPrefix 'errors'.
*
* @param t - the i18next-react t function
* @returns the translated string
* @example
* const {t} = useTranslation('explore', { keyPrefix: 'errors' })
* t('NameOfErrorClassThatExtendsIpldExploreError')
*/
toString (t: TFunction<'translation', 'translation'>): string {
return t(this.name, this.options)
}
}
export class BlockFetchTimeoutError extends IpldExploreError {}
export class CARFetchError extends IpldExploreError {}