Skip to content

Commit 9b3c847

Browse files
authored
Merge pull request #4151 from paulkaplan/show-error-id
Show error ID if available from Raven and report react errors
2 parents 6355abe + 40ca680 commit 9b3c847

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/components/crash-message/crash-message.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ const CrashMessage = props => (
2929
id="gui.crashMessage.description"
3030
/>
3131
</p>
32+
{props.eventId && (
33+
<p>
34+
<FormattedMessage
35+
defaultMessage="Your error was logged with id {errorId}"
36+
description="Message to inform the user that page has crashed."
37+
id="gui.crashMessage.errorNumber"
38+
values={{
39+
errorId: props.eventId
40+
}}
41+
/>
42+
</p>
43+
)}
3244
<button
3345
className={styles.reloadButton}
3446
onClick={props.onReload}
@@ -44,6 +56,7 @@ const CrashMessage = props => (
4456
);
4557

4658
CrashMessage.propTypes = {
59+
eventId: PropTypes.string,
4760
onReload: PropTypes.func.isRequired
4861
};
4962

src/containers/error-boundary.jsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class ErrorBoundary extends React.Component {
1212
constructor (props) {
1313
super(props);
1414
this.state = {
15-
hasError: false
15+
hasError: false,
16+
errorId: null
1617
};
1718
}
1819

@@ -24,7 +25,10 @@ class ErrorBoundary extends React.Component {
2425
};
2526

2627
// Display fallback UI
27-
this.setState({hasError: true});
28+
this.setState({
29+
hasError: true,
30+
errorId: window.Raven ? window.Raven.lastEventId() : null
31+
});
2832

2933
// Log errors to analytics, separating supported browsers from unsupported.
3034
if (supportedBrowser()) {
@@ -33,6 +37,9 @@ class ErrorBoundary extends React.Component {
3337
action: this.props.action,
3438
label: error.message
3539
});
40+
if (window.Raven) {
41+
window.Raven.captureException(error, {extra: info});
42+
}
3643
} else {
3744
analytics.event({
3845
category: 'Unsupported Browser Error',
@@ -56,7 +63,12 @@ class ErrorBoundary extends React.Component {
5663
render () {
5764
if (this.state.hasError) {
5865
if (supportedBrowser()) {
59-
return <CrashMessageComponent onReload={this.handleReload} />;
66+
return (
67+
<CrashMessageComponent
68+
eventId={this.state.errorId}
69+
onReload={this.handleReload}
70+
/>
71+
);
6072
}
6173
return (<BrowserModalComponent
6274
isRtl={this.props.isRtl}

0 commit comments

Comments
 (0)