summaryrefslogtreecommitdiffhomepage
path: root/frontend/src/components/ErrorBoundary.tsx
blob: 4e39dd9dc373bfacf5b04d2bfb7c5194d3894c3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Component, PropsWithChildren } from "react";
import UIError from "@/pages/errors/UIError";

interface State {
  error: Error | null;
}

class ErrorBoundary extends Component<PropsWithChildren, State> {
  constructor(props: object) {
    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;