-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
4 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,52 @@ | ||
import { Container } from '@material-ui/core'; | ||
import { DialogBox } from 'components/UI/DialogBox/DialogBox'; | ||
import React, { Component } from 'react'; | ||
|
||
class ErrorBoundary extends Component<any, any> { | ||
constructor(props: any) { | ||
super(props); | ||
this.state = { hasError: false }; | ||
} | ||
|
||
static getDerivedStateFromError(error: any) { | ||
console.log(error); | ||
// Update state so the next render will show the fallback UI. | ||
return { hasError: true }; | ||
} | ||
|
||
componentDidCatch(error: any, errorInfo: any) { | ||
console.log(error, errorInfo); | ||
// You can also log the error to an error reporting service | ||
// logErrorToMyService(error, errorInfo); | ||
} | ||
|
||
render() { | ||
const { hasError } = this.state; | ||
const { children } = this.props; | ||
if (hasError) { | ||
// You can render any custom fallback UI | ||
return ( | ||
<Container> | ||
<div data-testid="errorMessage"> | ||
<DialogBox | ||
title="Error in rendering" | ||
colorOk="secondary" | ||
handleOk={() => {}} | ||
handleCancel={() => {}} | ||
buttonOk="Ok" | ||
skipCancel | ||
alignButtons="center" | ||
contentAlign="center" | ||
> | ||
An error has occurred! | ||
</DialogBox> | ||
</div> | ||
</Container> | ||
); | ||
} | ||
|
||
return children; | ||
} | ||
} | ||
|
||
export default ErrorBoundary; |
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