@@ -10,7 +10,7 @@ export class BrowserGlobalHandlerPlugin implements IEventPlugin {
1010 public priority : number = 100 ;
1111 public name : string = "BrowserGlobalHandlerPlugin" ;
1212
13- private _client : ExceptionlessClient = null ;
13+ private _client : ExceptionlessClient | undefined ;
1414
1515 public startup ( context : PluginContext ) : Promise < void > {
1616 if ( this . _client ) {
@@ -21,7 +21,7 @@ export class BrowserGlobalHandlerPlugin implements IEventPlugin {
2121
2222 // TODO: Discus if we want to unwire this handler in suspend?
2323 window . addEventListener ( "error" , event => {
24- void this . _client . submitUnhandledException ( this . getError ( event ) , "onerror" ) ;
24+ void this . _client ? .submitUnhandledException ( this . getError ( event ) , "onerror" ) ;
2525 } ) ;
2626
2727 window . addEventListener ( "unhandledrejection" , event => {
@@ -35,18 +35,18 @@ export class BrowserGlobalHandlerPlugin implements IEventPlugin {
3535 // eslint-disable-next-line no-empty
3636 } catch ( ex ) { }
3737
38- void this . _client . submitUnhandledException ( error , "onunhandledrejection" ) ;
38+ void this . _client ? .submitUnhandledException ( error , "onunhandledrejection" ) ;
3939 } ) ;
4040
4141
4242 if ( typeof $ !== "undefined" && $ ( document ) ) {
4343 $ ( document ) . ajaxError ( ( event : Event , xhr : { responseText : string , status : number } , settings : { data : unknown , url : string } , error : string ) => {
4444 if ( xhr . status === 404 ) {
4545 // TODO: Handle async
46- void this . _client . submitNotFound ( settings . url ) ;
46+ void this . _client ? .submitNotFound ( settings . url ) ;
4747 } else if ( xhr . status !== 401 ) {
4848 // TODO: Handle async
49- void this . _client . createUnhandledException ( new Error ( error ) , "JQuery.ajaxError" )
49+ void this . _client ? .createUnhandledException ( new Error ( error ) , "JQuery.ajaxError" )
5050 . setSource ( settings . url )
5151 . setProperty ( "status" , xhr . status )
5252 . setProperty ( "request" , settings . data )
@@ -69,12 +69,15 @@ export class BrowserGlobalHandlerPlugin implements IEventPlugin {
6969 let msg : string = message || event . error ;
7070 if ( msg ) {
7171 const errorNameRegex : RegExp = / ^ (?: [ U u ] n c a u g h t (?: e x c e p t i o n : ) ? ) ? (?: ( (?: A g g r e g a t e | E v a l | I n t e r n a l | R a n g e | R e f e r e n c e | S y n t a x | T y p e | U R I | ) E r r o r ) : ) ? ( .* ) $ / i;
72- const [ _ , errorName , errorMessage ] = errorNameRegex . exec ( msg ) ;
73- if ( errorName ) {
74- name = errorName ;
75- }
76- if ( errorMessage ) {
77- msg = errorMessage ;
72+ const regexResult = errorNameRegex . exec ( msg ) ;
73+ if ( regexResult ) {
74+ const [ _ , errorName , errorMessage ] = regexResult ;
75+ if ( errorName ) {
76+ name = errorName ;
77+ }
78+ if ( errorMessage ) {
79+ msg = errorMessage ;
80+ }
7881 }
7982 }
8083
0 commit comments