1- import { getCurrentHub } from '@sentry/core' ;
1+ import { getCurrentHub , Scope } from '@sentry/core' ;
22import { Integration } from '@sentry/types' ;
33
44/** Global Promise Rejection handler */
@@ -25,29 +25,33 @@ export class OnUnhandledRejection implements Integration {
2525 * @param promise promise
2626 */
2727 public sendUnhandledPromise ( reason : any , promise : any ) : void {
28- if ( ! getCurrentHub ( ) . getIntegration ( OnUnhandledRejection ) ) {
28+ const hub = getCurrentHub ( ) ;
29+
30+ if ( ! hub . getIntegration ( OnUnhandledRejection ) ) {
2931 return ;
3032 }
33+
3134 const context = ( promise . domain && promise . domain . sentryContext ) || { } ;
32- getCurrentHub ( ) . withScope ( ( ) => {
33- getCurrentHub ( ) . configureScope ( scope => {
34- // Preserve backwards compatibility with raven-node for now
35- if ( context . user ) {
36- scope . setUser ( context . user ) ;
37- }
38- if ( context . tags ) {
39- Object . keys ( context . tags ) . forEach ( key => {
40- scope . setTag ( key , context . tags [ key ] ) ;
41- } ) ;
42- }
43- if ( context . extra ) {
44- Object . keys ( context . extra ) . forEach ( key => {
45- scope . setExtra ( key , context . extra [ key ] ) ;
46- } ) ;
47- }
48- scope . setExtra ( 'unhandledPromiseRejection' , true ) ;
49- } ) ;
50- getCurrentHub ( ) . captureException ( reason , { originalException : promise } ) ;
35+
36+ hub . withScope ( ( scope : Scope ) => {
37+ scope . setExtra ( 'unhandledPromiseRejection' , true ) ;
38+
39+ // Preserve backwards compatibility with raven-node for now
40+ if ( context . user ) {
41+ scope . setUser ( context . user ) ;
42+ }
43+ if ( context . tags ) {
44+ Object . keys ( context . tags ) . forEach ( key => {
45+ scope . setTag ( key , context . tags [ key ] ) ;
46+ } ) ;
47+ }
48+ if ( context . extra ) {
49+ Object . keys ( context . extra ) . forEach ( key => {
50+ scope . setExtra ( key , context . extra [ key ] ) ;
51+ } ) ;
52+ }
53+
54+ hub . captureException ( reason , { originalException : promise } ) ;
5155 } ) ;
5256 }
5357}
0 commit comments