@@ -70,7 +70,7 @@ extend(Raven.prototype, {
70
70
} ,
71
71
72
72
install : function install ( cb ) {
73
- patchGlobal ( this , cb ) ;
73
+ registerGlobalHandlers ( this , cb ) ;
74
74
return this ;
75
75
} ,
76
76
@@ -390,18 +390,7 @@ defaultInstance.disableConsoleAlerts = utils.disableConsoleAlerts;
390
390
391
391
module . exports = defaultInstance ;
392
392
393
- function patchGlobal ( client , cb ) {
394
- // handle when the first argument is the callback, with no client specified
395
- if ( typeof client === 'function' ) {
396
- cb = client ;
397
- client = new Client ( ) ;
398
- // first argument is a string DSN
399
- } else if ( typeof client === 'string' ) {
400
- client = new Client ( client ) ;
401
- }
402
- // at the end, if we still don't have a Client, let's make one!
403
- ! ( client instanceof Raven ) && ( client = new Client ( ) ) ;
404
-
393
+ function registerGlobalHandlers ( client , cb ) {
405
394
var called = false ;
406
395
process . on ( 'uncaughtException' , function ( err ) {
407
396
if ( cb ) { // bind event listeners only if a callback was supplied
@@ -423,11 +412,33 @@ function patchGlobal(client, cb) {
423
412
424
413
client . once ( 'logged' , onLogged ) ;
425
414
client . once ( 'error' , onError ) ;
426
- }
427
415
428
- called = true ;
416
+ called = true ;
417
+ }
429
418
430
419
var eventId = client . captureException ( err ) ;
431
420
return utils . consoleAlert ( 'uncaughtException: ' + eventId ) ;
432
421
} ) ;
422
+
423
+ process . on ( 'unhandledRejection' , function ( reason ) {
424
+ var eventId = client . captureException ( reason , function ( sendErr ) {
425
+ cb && cb ( ! sendErr , reason ) ;
426
+ } ) ;
427
+ return utils . consoleAlert ( 'unhandledRejection: ' + eventId ) ;
428
+ } ) ;
429
+ }
430
+
431
+ function patchGlobal ( client , cb ) {
432
+ // handle when the first argument is the callback, with no client specified
433
+ if ( typeof client === 'function' ) {
434
+ cb = client ;
435
+ client = new Client ( ) ;
436
+ // first argument is a string DSN
437
+ } else if ( typeof client === 'string' ) {
438
+ client = new Client ( client ) ;
439
+ }
440
+ // at the end, if we still don't have a Client, let's make one!
441
+ ! ( client instanceof Raven ) && ( client = new Client ( ) ) ;
442
+
443
+ registerGlobalHandlers ( client , cb ) ;
433
444
}
0 commit comments