Show error ID and report React errors to Sentry

This commit is contained in:
Paul Kaplan 2018-12-19 13:47:17 -05:00
parent ad4442a310
commit 8af12ec0e1
3 changed files with 27 additions and 3 deletions

View file

@ -20,6 +20,16 @@ const CrashMessage = props => (
<p>
<FormattedMessage id="general.unhandledError" />
</p>
{props.eventId && (
<p>
<FormattedMessage
id="general.errorIdentifier"
values={{
errorId: props.eventId
}}
/>
</p>
)}
<Button
className=""
onClick={props.onBack}
@ -32,6 +42,7 @@ const CrashMessage = props => (
CrashMessage.propTypes = {
className: PropTypes.string,
eventId: PropTypes.string,
onBack: PropTypes.func
};

View file

@ -8,13 +8,20 @@ class ErrorBoundary extends React.Component {
constructor (props) {
super(props);
this.state = {
hasError: false
hasError: false,
errorId: null
};
}
componentDidCatch (error, info) {
// Display fallback UI
this.setState({hasError: true});
this.setState({
hasError: true,
errorId: window.Raven ? window.Raven.lastEventId() : null
});
if (window.Raven) {
window.Raven.captureException(error, {extra: info});
}
log.error(`Unhandled Error: ${error}, info: ${info}`);
}
@ -24,7 +31,12 @@ class ErrorBoundary extends React.Component {
render () {
if (this.state.hasError) {
return <CrashMessageComponent onBack={this.handleBack} />;
return (
<CrashMessageComponent
eventId={this.state.eventId}
onBack={this.handleBack}
/>
);
}
return this.props.children;
}

View file

@ -18,6 +18,7 @@
"general.dmca": "DMCA",
"general.emailAddress": "Email Address",
"general.error": "Oops! Something went wrong",
"general.errorIdentifier": "Your error was logged with id {errorId}",
"general.explore": "Explore",
"general.faq": "FAQ",
"general.female": "Female",