-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fetch timeout has better error UX (#378)
* fix: fetch timeout has better error UX * chore: fix property used to get error name
- Loading branch information
Showing
6 changed files
with
54 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
import type IpldExploreError from '../../lib/errors' | ||
|
||
export interface IpldExploreErrorComponentProps { | ||
error?: IpldExploreError | ||
} | ||
|
||
export function IpldExploreErrorComponent ({ error }: IpldExploreErrorComponentProps): JSX.Element | null { | ||
const { t } = useTranslation('explore', { keyPrefix: 'errors' }) | ||
if (error == null) return null | ||
|
||
return ( | ||
<div className='bg-red white pa3 lh-copy'> | ||
<div>{error.toString(t)}</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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', undefined, 'translation'>): string { | ||
return t(this.name, this.options) | ||
} | ||
} | ||
|
||
export class BlockFetchTimeoutError extends IpldExploreError {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters