11import React from 'react' ;
22import PropTypes from 'prop-types' ;
33import { connect } from 'react-redux' ;
4- import bowser from 'bowser' ;
54import BrowserModalComponent from '../components/browser-modal/browser-modal.jsx' ;
65import CrashMessageComponent from '../components/crash-message/crash-message.jsx' ;
76import log from '../lib/log.js' ;
87import supportedBrowser from '../lib/supported-browser' ;
9- import analytics from '../lib/analytics' ;
108
119class ErrorBoundary extends React . Component {
1210 constructor ( props ) {
@@ -24,36 +22,23 @@ class ErrorBoundary extends React.Component {
2422 message : 'Unknown error'
2523 } ;
2624
25+ // Log errors to analytics, leaving out supported browsers from unsupported.
26+ if ( supportedBrowser ( ) && window . Sentry ) {
27+ window . Sentry . withScope ( scope => {
28+ Object . keys ( info ) . forEach ( key => {
29+ scope . setExtra ( key , info [ key ] ) ;
30+ } ) ;
31+ scope . setExtra ( 'action' , this . props . action ) ;
32+ window . Sentry . captureException ( error ) ;
33+ } ) ;
34+ }
35+
2736 // Display fallback UI
2837 this . setState ( {
2938 hasError : true ,
3039 errorId : window . Sentry ? window . Sentry . lastEventId ( ) : null
3140 } ) ;
3241
33- // Log errors to analytics, separating supported browsers from unsupported.
34- if ( supportedBrowser ( ) ) {
35- analytics . event ( {
36- category : 'error' ,
37- action : this . props . action ,
38- label : error . message
39- } ) ;
40- if ( window . Sentry ) {
41- window . Sentry . withScope ( scope => {
42- Object . keys ( info ) . forEach ( key => {
43- scope . setExtra ( key , info [ key ] ) ;
44- } ) ;
45- scope . setExtra ( 'action' , this . props . action ) ;
46- window . Sentry . captureException ( error ) ;
47- } ) ;
48- }
49- } else {
50- analytics . event ( {
51- category : 'Unsupported Browser Error' ,
52- action : `(Unsupported Browser) ${ this . props . action } ` ,
53- label : `${ bowser . name } ${ error . message } `
54- } ) ;
55- }
56-
5742 // Log error locally for debugging as well.
5843 log . error ( `Unhandled Error: ${ error . stack } \nComponent stack: ${ info . componentStack } ` ) ;
5944 }
0 commit comments