2019-08-07 06:02:36 +01:00
|
|
|
export default class ErrorBoundary extends PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.node,
|
2020-02-29 15:42:47 +00:00
|
|
|
}
|
2019-08-07 06:02:36 +01:00
|
|
|
|
|
|
|
state = {
|
|
|
|
hasError: false,
|
|
|
|
stackTrace: undefined,
|
|
|
|
componentStack: undefined,
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidCatch(error, info) {
|
|
|
|
this.setState({
|
|
|
|
hasError: true,
|
|
|
|
stackTrace: error.stack,
|
|
|
|
componentStack: info && info.componentStack,
|
2020-02-29 15:42:47 +00:00
|
|
|
})
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2020-02-29 15:42:47 +00:00
|
|
|
const { hasError } = this.state
|
|
|
|
|
|
|
|
if (!hasError) return this.props.children
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-02-29 15:42:47 +00:00
|
|
|
// : todo : custom error page
|
2019-08-07 06:02:36 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='error-boundary'>
|
|
|
|
<div className='error-boundary__container'>
|
|
|
|
<a className='error-boundary__link' href='/home'>Return Home</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-02-29 15:42:47 +00:00
|
|
|
)
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|