mirror of
https://git.bsd.gay/fef/nyastodon.git
synced 2024-12-28 13:33:44 +01:00
40 lines
734 B
JavaScript
40 lines
734 B
JavaScript
|
import React from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import illustration from '../../images/elephant_ui_disappointed.svg';
|
||
|
|
||
|
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>
|
||
|
<img src={illustration} alt='' />
|
||
|
</div>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|