summaryrefslogtreecommitdiff
path: root/src/components/ErrorBoundary.tsx
blob: ed395d12e779268d48c9253bc1b21aad855630b1 (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
30
31
32
33
import * as React from 'react';

// import { getSentry } from '../misc/sentry';
import { deriveMessageFromError, Err } from '../misc/errors';

import ErrorBoundaryFallback from './ErrorBoundaryFallback';

type Props = {
  children: React.ReactNode;
};

type State = {
  error?: Err;
};

class ErrorBoundary extends React.Component<Props, State> {
  state = { error: null };

  static getDerivedStateFromError(error: Err) {
    return { error };
  }

  render() {
    if (this.state.error) {
      const { message, detail } = deriveMessageFromError(this.state.error);
      return <ErrorBoundaryFallback message={message} detail={detail} />;
    } else {
      return this.props.children;
    }
  }
}

export default ErrorBoundary;