2019-07-02 08:10:25 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
|
2019-08-03 07:00:45 +01:00
|
|
|
import './index.scss';
|
|
|
|
|
2019-07-29 20:20:00 +01:00
|
|
|
export default class ErrorBoundary extends PureComponent {
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
children: PropTypes.node,
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
hasError: false,
|
|
|
|
stackTrace: undefined,
|
|
|
|
componentStack: undefined,
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidCatch(error, info) {
|
|
|
|
this.setState({
|
|
|
|
hasError: true,
|
|
|
|
stackTrace: error.stack,
|
|
|
|
componentStack: info && info.componentStack,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { hasError } = this.state;
|
|
|
|
|
2019-08-03 07:00:45 +01:00
|
|
|
if (!hasError) return this.props.children;
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='error-boundary'>
|
2019-08-03 07:00:45 +01:00
|
|
|
<div className='error-boundary__container'>
|
2019-07-02 08:10:25 +01:00
|
|
|
<FormattedMessage id='alert.unexpected.message' defaultMessage='Error' />
|
2019-08-03 07:00:45 +01:00
|
|
|
<a className='error-boundary__link' href='/home'>Return Home</a>
|
2019-07-02 08:10:25 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|