mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-14 11:05:06 +01:00
6a125a593d
Co-authored-by: Jip Frijlink <JipFr@users.noreply.github.com>
45 lines
833 B
TypeScript
45 lines
833 B
TypeScript
import { Component } from "react";
|
|
|
|
import { ErrorPart } from "@/pages/parts/errors/ErrorPart";
|
|
|
|
interface ErrorBoundaryState {
|
|
error?: {
|
|
error: any;
|
|
errorInfo: any;
|
|
};
|
|
}
|
|
|
|
export class ErrorBoundary extends Component<
|
|
Record<string, unknown>,
|
|
ErrorBoundaryState
|
|
> {
|
|
constructor(props: { children: any }) {
|
|
super(props);
|
|
this.state = {
|
|
error: undefined,
|
|
};
|
|
}
|
|
|
|
componentDidCatch(error: any, errorInfo: any) {
|
|
console.error("Render error caught", error, errorInfo);
|
|
this.setState((s) => ({
|
|
...s,
|
|
error: {
|
|
error,
|
|
errorInfo,
|
|
},
|
|
}));
|
|
}
|
|
|
|
render() {
|
|
if (!this.state.error) return this.props.children as any;
|
|
|
|
return (
|
|
<ErrorPart
|
|
error={this.state.error.error}
|
|
errorInfo={this.state.error.errorInfo}
|
|
/>
|
|
);
|
|
}
|
|
}
|