summaryrefslogtreecommitdiff
path: root/src/components/ErrorBoundary.js
blob: 384a2917606f37bd3b6252d304c3c967869b6ec2 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { getSentry } from '../misc/sentry';
import ErrorBoundaryFallback from 'c/ErrorBoundaryFallback';

// XXX this is no Hook equivalents for componentDidCatch
// we have to use class for now

class ErrorBoundary extends Component {
  static propTypes = {
    children: PropTypes.node
  };

  state = { error: null };

  loadSentry = async () => {
    if (this.sentry) return this.sentry;
    const x = await getSentry();
    this.sentry = x;
    return this.sentry;
  };

  componentDidMount() {
    // this.loadSentry();
  }

  componentDidCatch(error, errorInfo) {
    // eslint-disable-next-line no-console
    console.log(error, errorInfo);
    // this.setState({ error });
    // this.loadSentry().then(Sentry => {
    //   Sentry.withScope(scope => {
    //     Object.keys(errorInfo).forEach(key => {
    //       scope.setExtra(key, errorInfo[key]);
    //     });
    //     Sentry.captureException(error);
    //   });
    // });
  }

  showReportDialog = () => {
    this.loadSentry().then(Sentry => Sentry.showReportDialog());
  };

  render() {
    if (this.state.error) {
      //render fallback UI
      // return <a onClick={this.showReportDialog}>Report feedback</a>;
      return <ErrorBoundaryFallback />;
    } else {
      return this.props.children;
    }
  }
}

export default ErrorBoundary;