mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 09:35:56 -05:00
Show error ID and report React errors to Sentry
This commit is contained in:
parent
ad4442a310
commit
8af12ec0e1
3 changed files with 27 additions and 3 deletions
|
@ -20,6 +20,16 @@ const CrashMessage = props => (
|
||||||
<p>
|
<p>
|
||||||
<FormattedMessage id="general.unhandledError" />
|
<FormattedMessage id="general.unhandledError" />
|
||||||
</p>
|
</p>
|
||||||
|
{props.eventId && (
|
||||||
|
<p>
|
||||||
|
<FormattedMessage
|
||||||
|
id="general.errorIdentifier"
|
||||||
|
values={{
|
||||||
|
errorId: props.eventId
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
className=""
|
className=""
|
||||||
onClick={props.onBack}
|
onClick={props.onBack}
|
||||||
|
@ -32,6 +42,7 @@ const CrashMessage = props => (
|
||||||
|
|
||||||
CrashMessage.propTypes = {
|
CrashMessage.propTypes = {
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
|
eventId: PropTypes.string,
|
||||||
onBack: PropTypes.func
|
onBack: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,20 @@ class ErrorBoundary extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
hasError: false
|
hasError: false,
|
||||||
|
errorId: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidCatch (error, info) {
|
componentDidCatch (error, info) {
|
||||||
// Display fallback UI
|
// 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}`);
|
log.error(`Unhandled Error: ${error}, info: ${info}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +31,12 @@ class ErrorBoundary extends React.Component {
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
if (this.state.hasError) {
|
if (this.state.hasError) {
|
||||||
return <CrashMessageComponent onBack={this.handleBack} />;
|
return (
|
||||||
|
<CrashMessageComponent
|
||||||
|
eventId={this.state.eventId}
|
||||||
|
onBack={this.handleBack}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return this.props.children;
|
return this.props.children;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
"general.dmca": "DMCA",
|
"general.dmca": "DMCA",
|
||||||
"general.emailAddress": "Email Address",
|
"general.emailAddress": "Email Address",
|
||||||
"general.error": "Oops! Something went wrong",
|
"general.error": "Oops! Something went wrong",
|
||||||
|
"general.errorIdentifier": "Your error was logged with id {errorId}",
|
||||||
"general.explore": "Explore",
|
"general.explore": "Explore",
|
||||||
"general.faq": "FAQ",
|
"general.faq": "FAQ",
|
||||||
"general.female": "Female",
|
"general.female": "Female",
|
||||||
|
|
Loading…
Reference in a new issue