pstream is dead; long live pstream
taciturnaxolotl.github.io/pstream-ng/
1import { Component } from "react";
2
3import { ErrorPart } from "@/pages/parts/errors/ErrorPart";
4
5interface ErrorBoundaryState {
6 error?: {
7 error: any;
8 errorInfo: any;
9 };
10}
11
12export class ErrorBoundary extends Component<
13 Record<string, unknown>,
14 ErrorBoundaryState
15> {
16 constructor(props: { children: any }) {
17 super(props);
18 this.state = {
19 error: undefined,
20 };
21 }
22
23 componentDidCatch(error: any, errorInfo: any) {
24 console.error("Render error caught", error, errorInfo);
25 this.setState((s) => ({
26 ...s,
27 error: {
28 error,
29 errorInfo,
30 },
31 }));
32 }
33
34 render() {
35 if (!this.state.error) return this.props.children as any;
36
37 return (
38 <ErrorPart
39 error={this.state.error.error}
40 errorInfo={this.state.error.errorInfo}
41 />
42 );
43 }
44}