Common: Components: ErrorBoundary: fix

This commit is contained in:
Viktor Fomin 2023-06-01 12:05:06 +03:00
parent e3b6f793c4
commit 4ab3461fda

View File

@ -5,24 +5,23 @@ import Error520 from "client/Error520";
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false, error: null };
this.state = { error: null };
}
// eslint-disable-next-line no-unused-vars
static getDerivedStateFromError(error) {
// Update state so the next render will show the fallback UI.
return { hasError: true };
return { error: error ?? "Unhandled exception" };
}
componentDidCatch(error, errorInfo) {
// You can also log the error to an error reporting service
console.error(error, errorInfo);
this.setState({ error: error });
this.props.onError && this.props.onError();
}
render() {
if (this.state.hasError && this.state.error) {
if (this.state.error) {
// You can render any custom fallback UI
return <Error520 errorLog={this.state.error} />;
}