gab-social/app/javascript/gabsocial/components/error_boundary/index.js

41 lines
863 B
JavaScript
Raw Normal View History

2019-07-02 08:10:25 +01:00
import { FormattedMessage } from 'react-intl';
import './index.scss';
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;
if (!hasError) return this.props.children;
2019-07-02 08:10:25 +01:00
return (
<div className='error-boundary'>
<div className='error-boundary__container'>
2019-07-02 08:10:25 +01:00
<FormattedMessage id='alert.unexpected.message' defaultMessage='Error' />
<a className='error-boundary__link' href='/home'>Return Home</a>
2019-07-02 08:10:25 +01:00
</div>
</div>
);
}
}