You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
963 B
63 lines
963 B
6 years ago
|
import PropTypes from 'prop-types';
|
||
|
import React, { Component } from 'react';
|
||
|
import * as sentry from '@sentry/browser';
|
||
|
|
||
|
class ErrorBoundary extends Component {
|
||
|
|
||
|
//
|
||
|
// Lifecycle
|
||
|
|
||
|
constructor(props, context) {
|
||
|
super(props, context);
|
||
|
|
||
|
this.state = {
|
||
|
error: null,
|
||
|
info: null
|
||
|
};
|
||
|
}
|
||
|
|
||
|
componentDidCatch(error, info) {
|
||
|
this.setState({
|
||
|
error,
|
||
|
info
|
||
|
});
|
||
|
|
||
|
sentry.captureException(error);
|
||
|
}
|
||
|
|
||
|
//
|
||
|
// Render
|
||
|
|
||
|
render() {
|
||
|
const {
|
||
|
children,
|
||
|
errorComponent: ErrorComponent,
|
||
|
...otherProps
|
||
|
} = this.props;
|
||
|
|
||
|
const {
|
||
|
error,
|
||
|
info
|
||
|
} = this.state;
|
||
|
|
||
|
if (error) {
|
||
|
return (
|
||
|
<ErrorComponent
|
||
|
error={error}
|
||
|
info={info}
|
||
|
{...otherProps}
|
||
|
/>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return children;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
ErrorBoundary.propTypes = {
|
||
|
children: PropTypes.node.isRequired,
|
||
|
errorComponent: PropTypes.func.isRequired
|
||
|
};
|
||
|
|
||
|
export default ErrorBoundary;
|