2020-10-16 12:38:04 +00:00
|
|
|
import React from "react";
|
|
|
|
import PropTypes from "prop-types";
|
2021-03-03 08:15:11 +00:00
|
|
|
import Error520 from "studio/Error520";
|
2020-02-03 08:36:25 +00:00
|
|
|
|
|
|
|
class ErrorBoundary extends React.Component {
|
2020-10-16 12:38:04 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = { hasError: false };
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
static getDerivedStateFromError(error) {
|
|
|
|
// Update state so the next render will show the fallback UI.
|
|
|
|
return { hasError: true };
|
2020-02-03 08:36:25 +00:00
|
|
|
}
|
|
|
|
|
2020-10-16 12:38:04 +00:00
|
|
|
componentDidCatch(error, errorInfo) {
|
|
|
|
// You can also log the error to an error reporting service
|
|
|
|
console.error(error, errorInfo);
|
2020-02-03 08:36:25 +00:00
|
|
|
}
|
|
|
|
|
2020-10-16 12:38:04 +00:00
|
|
|
render() {
|
|
|
|
if (this.state.hasError) {
|
|
|
|
// You can render any custom fallback UI
|
2021-03-03 08:15:11 +00:00
|
|
|
return <Error520 />;
|
2020-10-16 12:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.props.children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorBoundary.propTypes = {
|
|
|
|
children: PropTypes.any,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ErrorBoundary;
|