erikbcox / quick-math-for-ben

Ionic 4 with React App for doing math facts
0 stars 0 forks source link

install sentry #6

Closed erikbcox closed 5 years ago

erikbcox commented 5 years ago

https://www.npmjs.com/package/@sentry/browser https://docs.sentry.io/platforms/javascript/react/ http://getsentry.github.io/sentry-javascript/

erikbcox commented 5 years ago
import * as Sentry from '@sentry/browser';

// Sentry.init({
//  dsn: "https://34517b80698e4fd1b9382ceed08d8030@sentry.io/1436213"
// });
// should have been called before using it here
// ideally before even rendering your react app

class ExampleBoundary extends Component {
    constructor(props) {
        super(props);
        this.state = { error: null, eventId: null };
    }

    componentDidCatch(error, errorInfo) {
      this.setState({ error });
      Sentry.withScope(scope => {
          scope.setExtras(errorInfo);
          const eventId = Sentry.captureException(error);
          this.setState({eventId})
      });
    }

    render() {
        if (this.state.error) {
            //render fallback UI
            return (
              <a onClick={() => Sentry.showReportDialog({ eventId: this.state.eventId })}>Report feedback</a>
            );
        } else {
            //when there's not an error, render children untouched
            return this.props.children;
        }
    }
}