@@ -10,7 +10,7 @@ export class BrowserGlobalHandlerPlugin implements IEventPlugin {
10
10
public priority : number = 100 ;
11
11
public name : string = "BrowserGlobalHandlerPlugin" ;
12
12
13
- private _client : ExceptionlessClient = null ;
13
+ private _client : ExceptionlessClient | undefined ;
14
14
15
15
public startup ( context : PluginContext ) : Promise < void > {
16
16
if ( this . _client ) {
@@ -21,7 +21,7 @@ export class BrowserGlobalHandlerPlugin implements IEventPlugin {
21
21
22
22
// TODO: Discus if we want to unwire this handler in suspend?
23
23
window . addEventListener ( "error" , event => {
24
- void this . _client . submitUnhandledException ( this . getError ( event ) , "onerror" ) ;
24
+ void this . _client ? .submitUnhandledException ( this . getError ( event ) , "onerror" ) ;
25
25
} ) ;
26
26
27
27
window . addEventListener ( "unhandledrejection" , event => {
@@ -35,18 +35,18 @@ export class BrowserGlobalHandlerPlugin implements IEventPlugin {
35
35
// eslint-disable-next-line no-empty
36
36
} catch ( ex ) { }
37
37
38
- void this . _client . submitUnhandledException ( error , "onunhandledrejection" ) ;
38
+ void this . _client ? .submitUnhandledException ( error , "onunhandledrejection" ) ;
39
39
} ) ;
40
40
41
41
42
42
if ( typeof $ !== "undefined" && $ ( document ) ) {
43
43
$ ( document ) . ajaxError ( ( event : Event , xhr : { responseText : string , status : number } , settings : { data : unknown , url : string } , error : string ) => {
44
44
if ( xhr . status === 404 ) {
45
45
// TODO: Handle async
46
- void this . _client . submitNotFound ( settings . url ) ;
46
+ void this . _client ? .submitNotFound ( settings . url ) ;
47
47
} else if ( xhr . status !== 401 ) {
48
48
// TODO: Handle async
49
- void this . _client . createUnhandledException ( new Error ( error ) , "JQuery.ajaxError" )
49
+ void this . _client ? .createUnhandledException ( new Error ( error ) , "JQuery.ajaxError" )
50
50
. setSource ( settings . url )
51
51
. setProperty ( "status" , xhr . status )
52
52
. setProperty ( "request" , settings . data )
@@ -69,12 +69,15 @@ export class BrowserGlobalHandlerPlugin implements IEventPlugin {
69
69
let msg : string = message || event . error ;
70
70
if ( msg ) {
71
71
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
+ }
78
81
}
79
82
}
80
83
0 commit comments