Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
Pass original error to beforeNotifyCallbacks (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
kattrali authored Jun 5, 2017
1 parent 992fc9e commit 906700a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/bugsnag.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ Bugsnag.notify = function(error, options, cb) {
notification = new Notification(bugsnagErrors, options);
if (Configuration.sendCode === true) {
notification.loadCode(function () {
notification.deliver(cb);
notification.deliver(cb, error);
});
} else {
notification.deliver(cb);
notification.deliver(cb, error);
}
};

Expand Down
4 changes: 2 additions & 2 deletions lib/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ function Notification(bugsnagErrors, options) {
this.events = [event];
}

Notification.prototype.deliver = function(cb) {
Notification.prototype.deliver = function(cb, originalError) {

// run before notify callbacks
var shouldNotify = true;
Configuration.beforeNotifyCallbacks.forEach(function (callback) {
var ret = callback(this);
var ret = callback(this, originalError);
if (ret === false) {
shouldNotify = false;
}
Expand Down
18 changes: 18 additions & 0 deletions test/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,24 @@ describe("Notification", function() {

Configuration.beforeNotifyCallbacks = [];
});

it("should allow introspecting the original error object", function () {
function SpecialError(message) {
this.name = "SpecialError";
this.message = message;
this.customInfo = {times: "three"};
}
SpecialError.prototype = Object.create(Error.prototype);

var error = new SpecialError("there is a glitch");
Bugsnag.onBeforeNotify(function (notification, error) {
notification.events[0].metaData.customInfo = error.customInfo;
});
Bugsnag.notify(error);
deliverStub.firstCall.thisValue.events[0].metaData.customInfo.should.have.property("times", "three");

Configuration.beforeNotifyCallbacks = [];
});
});

describe("autoNotify", function() {
Expand Down

0 comments on commit 906700a

Please sign in to comment.