File tree 3 files changed +22
-8
lines changed
3 files changed +22
-8
lines changed Original file line number Diff line number Diff line change @@ -117,7 +117,7 @@ const registerEventHandlers = () => {
117
117
. querySelector ( "#throw-promise-unhandled-rejection" )
118
118
. addEventListener ( "click" , ( ) => {
119
119
const promiseFn = ( ) => new Promise ( function ( _ , reject ) {
120
- switch ( Math . floor ( Math . random ( ) * 4 ) ) {
120
+ switch ( Math . floor ( Math . random ( ) * 5 ) ) {
121
121
case 0 :
122
122
reject ( 0 ) ;
123
123
break ;
@@ -130,6 +130,8 @@ const registerEventHandlers = () => {
130
130
case 3 :
131
131
reject ( ) ;
132
132
break ;
133
+ case 4 :
134
+ throw new Error ( "Error thrown from promise" ) ;
133
135
}
134
136
} ) ;
135
137
Original file line number Diff line number Diff line change @@ -27,12 +27,24 @@ export class BrowserGlobalHandlerPlugin implements IEventPlugin {
27
27
28
28
window . addEventListener ( "unhandledrejection" , event => {
29
29
let reason : unknown = event . reason ;
30
- try {
31
- const detailReason = ( < { detail ?: { reason : string } } > event ) . detail ?. reason ;
32
- if ( detailReason ) {
33
- reason = detailReason ;
34
- }
35
- } catch ( ex ) { /* empty */ }
30
+ if ( ! ( reason instanceof Error ) ) {
31
+ try {
32
+ // Check for reason in legacy CustomEvents (https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent)
33
+ const detailReason = ( < { detail ?: { reason : string } } > event ) . detail ?. reason ;
34
+ if ( detailReason ) {
35
+ reason = detailReason ;
36
+ }
37
+ } catch ( ex ) { /* empty */ }
38
+ }
39
+
40
+ if ( ! ( reason instanceof Error ) ) {
41
+ try {
42
+ const error = event . reason . error ;
43
+ if ( error ) {
44
+ reason = error ;
45
+ }
46
+ } catch ( ex ) { /* empty */ }
47
+ }
36
48
37
49
const error : Error = toError ( reason , "Unhandled rejection" )
38
50
void this . _client ?. submitUnhandledException ( error , "onunhandledrejection" ) ;
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ export class NodeGlobalHandlerPlugin implements IEventPlugin {
23
23
void this . _client ?. submitUnhandledException ( error , "uncaughtException" ) ;
24
24
} ) ;
25
25
26
- process . addListener ( "unhandledRejection" , ( reason : unknown | null | undefined ) => {
26
+ process . addListener ( "unhandledRejection" , ( reason : unknown ) => {
27
27
const error : Error = toError ( reason , "Unhandled rejection" )
28
28
void this . _client ?. submitUnhandledException ( error , "unhandledRejection" ) ;
29
29
} ) ;
You can’t perform that action at this time.
0 commit comments