Skip to content

Commit a328678

Browse files
committed
Make unhandledRejection listener optional via .install param
1 parent 1b531b1 commit a328678

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lib/client.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,15 @@ extend(Raven.prototype, {
6969
return this;
7070
},
7171

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+
}
7481
return this;
7582
},
7683

@@ -368,7 +375,8 @@ extend(Raven.prototype, {
368375
},
369376
patchGlobal: function (cb) {
370377
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;
372380
}
373381
});
374382
Raven.prototype.get_ident = Raven.prototype.getIdent;
@@ -390,7 +398,7 @@ defaultInstance.disableConsoleAlerts = utils.disableConsoleAlerts;
390398

391399
module.exports = defaultInstance;
392400

393-
function registerGlobalHandlers(client, cb) {
401+
function registerExceptionHandler(client, cb) {
394402
var called = false;
395403
process.on('uncaughtException', function (err) {
396404
if (cb) { // bind event listeners only if a callback was supplied
@@ -419,7 +427,9 @@ function registerGlobalHandlers(client, cb) {
419427
var eventId = client.captureException(err);
420428
return utils.consoleAlert('uncaughtException: ' + eventId);
421429
});
430+
}
422431

432+
function registerRejectionHandler(client, cb) {
423433
process.on('unhandledRejection', function (reason) {
424434
var eventId = client.captureException(reason, function (sendErr) {
425435
cb && cb(!sendErr, reason);
@@ -440,5 +450,5 @@ function patchGlobal(client, cb) {
440450
// at the end, if we still don't have a Client, let's make one!
441451
!(client instanceof Raven) && (client = new Client());
442452

443-
registerGlobalHandlers(client, cb);
453+
registerExceptionHandler(client, cb);
444454
}

0 commit comments

Comments
 (0)