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

43 lines
851 B
JavaScript
Raw Normal View History

2019-07-02 08:10:25 +01:00
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
export default class ErrorBoundary extends React.PureComponent {
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;
}
return (
<div className='error-boundary'>
<div>
<FormattedMessage id='alert.unexpected.message' defaultMessage='Error' />
2019-07-04 00:29:54 +01:00
<a href='/home'>Return Home</a>
2019-07-02 08:10:25 +01:00
</div>
</div>
);
}
}