summaryrefslogtreecommitdiffhomepage
path: root/frontend/src/components/ErrorBoundary.tsx
blob: 9f6228e345ff48b5be7f47b91c22ea96e9bfe445 (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 UIError from "@/pages/errors/UIError";
import { Component } from "react";

interface State {
  error: Error | null;
}

class ErrorBoundary extends Component<object, 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;