-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: error boundary in layout to handle application errors / crashes (…
…#1108) Co-authored-by: Cody's Dad <40604284+AceTheCreator@users.noreply.github.com>
- Loading branch information
1 parent
950140c
commit 47bc184
Showing
7 changed files
with
77 additions
and
29 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
39 changes: 39 additions & 0 deletions
39
library/src/containers/ApplicationErrorHandler/ErrorBoundary.tsx
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,39 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { ReactNode } from 'react'; | ||
import { ErrorBoundary, FallbackProps } from 'react-error-boundary'; | ||
import { ErrorObject } from '../../types'; | ||
import { Error } from '../Error/Error'; | ||
|
||
interface Props { | ||
children: ReactNode; | ||
} | ||
|
||
function fallbackRender({ error }: FallbackProps) { | ||
const ErrorObject: ErrorObject = { | ||
title: 'Something went wrong', | ||
type: 'application-error', | ||
validationErrors: [ | ||
{ | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access | ||
title: error?.message, | ||
}, | ||
], | ||
}; | ||
return <Error error={ErrorObject} />; | ||
} | ||
|
||
const AsyncApiErrorBoundary = ({ children }: Props) => { | ||
const [key, setKey] = useState(0); | ||
|
||
useEffect(() => { | ||
setKey((prevKey) => prevKey + 1); | ||
}, [children]); | ||
|
||
return ( | ||
<ErrorBoundary key={key} fallbackRender={fallbackRender}> | ||
{children} | ||
</ErrorBoundary> | ||
); | ||
}; | ||
|
||
export default AsyncApiErrorBoundary; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.