-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[+] added an errorElement on router-dom to avoid the app from crashin…
…g completely if only a component has an issue
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useLocation, useRouteError } from 'react-router-dom'; | ||
import { PageState } from 'components'; | ||
import { analytics } from 'helpers'; | ||
import { faTimes } from 'icons/regular'; | ||
|
||
export const ErrorElement = () => { | ||
const { pathname } = useLocation(); | ||
const explorerVersion = process.env.VITE_APP_CACHE_BUST; | ||
const error = useRouteError(); | ||
console.error(error); | ||
|
||
if (explorerVersion !== undefined) { | ||
analytics.sendEvent({ | ||
action: 'error-encountered', | ||
label: pathname, | ||
explorerVersion | ||
}); | ||
} | ||
|
||
return ( | ||
<PageState | ||
icon={faTimes} | ||
title='Unexpected Error' | ||
description={ | ||
<div className='px-spacer'> | ||
<div className='text-break-all text-neutral-500'> | ||
Something went wrong. We are looking into the incident. | ||
</div> | ||
<button | ||
className='btn btn-sm btn-primary mx-auto mt-spacer' | ||
onClick={() => { | ||
window.location.reload(); | ||
}} | ||
> | ||
Reload | ||
</button> | ||
</div> | ||
} | ||
className='py-spacer m-auto' | ||
dataTestId='errorScreen' | ||
/> | ||
); | ||
}; |
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 @@ | ||
export * from './ErrorElement'; |
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