@@ -69,8 +69,15 @@ extend(Raven.prototype, {
69
69
return this ;
70
70
} ,
71
71
72
- install : function install ( cb ) {
73
- registerGlobalHandlers ( this , cb ) ;
72
+ install : function install ( opts , cb ) {
73
+ if ( typeof opts === 'function' ) {
74
+ cb = opts ;
75
+ }
76
+
77
+ registerExceptionHandler ( this , cb ) ;
78
+ if ( opts && opts . unhandledRejection ) {
79
+ registerRejectionHandler ( this , cb ) ;
80
+ }
74
81
return this ;
75
82
} ,
76
83
@@ -368,7 +375,8 @@ extend(Raven.prototype, {
368
375
} ,
369
376
patchGlobal : function ( cb ) {
370
377
utils . consoleAlert ( 'patchGlobal has been deprecated and will be removed in v2.0' ) ;
371
- return this . install ( cb ) ;
378
+ registerExceptionHandler ( this , cb ) ;
379
+ return this ;
372
380
}
373
381
} ) ;
374
382
Raven . prototype . get_ident = Raven . prototype . getIdent ;
@@ -390,7 +398,7 @@ defaultInstance.disableConsoleAlerts = utils.disableConsoleAlerts;
390
398
391
399
module . exports = defaultInstance ;
392
400
393
- function registerGlobalHandlers ( client , cb ) {
401
+ function registerExceptionHandler ( client , cb ) {
394
402
var called = false ;
395
403
process . on ( 'uncaughtException' , function ( err ) {
396
404
if ( cb ) { // bind event listeners only if a callback was supplied
@@ -419,7 +427,9 @@ function registerGlobalHandlers(client, cb) {
419
427
var eventId = client . captureException ( err ) ;
420
428
return utils . consoleAlert ( 'uncaughtException: ' + eventId ) ;
421
429
} ) ;
430
+ }
422
431
432
+ function registerRejectionHandler ( client , cb ) {
423
433
process . on ( 'unhandledRejection' , function ( reason ) {
424
434
var eventId = client . captureException ( reason , function ( sendErr ) {
425
435
cb && cb ( ! sendErr , reason ) ;
@@ -440,5 +450,5 @@ function patchGlobal(client, cb) {
440
450
// at the end, if we still don't have a Client, let's make one!
441
451
! ( client instanceof Raven ) && ( client = new Client ( ) ) ;
442
452
443
- registerGlobalHandlers ( client , cb ) ;
453
+ registerExceptionHandler ( client , cb ) ;
444
454
}
0 commit comments