2023-02-10 17:21:09 +00:00
|
|
|
import UIError from "@/pages/errors/UIError";
|
2023-06-04 15:03:59 +00:00
|
|
|
import { Component, PropsWithChildren } from "react";
|
2021-08-16 16:46:10 +00:00
|
|
|
|
|
|
|
interface State {
|
|
|
|
error: Error | null;
|
|
|
|
}
|
|
|
|
|
2023-06-04 15:03:59 +00:00
|
|
|
class ErrorBoundary extends Component<PropsWithChildren, State> {
|
2022-03-16 06:26:15 +00:00
|
|
|
constructor(props: object) {
|
2021-08-16 16:46:10 +00:00
|
|
|
super(props);
|
|
|
|
this.state = { error: null };
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidCatch(error: Error) {
|
|
|
|
this.setState({ error });
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { children } = this.props;
|
|
|
|
const { error } = this.state;
|
|
|
|
if (error) {
|
|
|
|
return <UIError error={error}></UIError>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ErrorBoundary;
|