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

Pass original error to pre-send callbacks #103

Merged
merged 1 commit into from
Jun 5, 2017

Conversation

kattrali
Copy link
Contributor

@kattrali kattrali commented Jun 3, 2017

Sometimes additional context available on the error instance is needed when creating error reports, which can then be used to attach metadata or decide to cancel the report. This change adds the original error which generated the report as a parameter to beforeNotifyCallbacks.

Here's an example of attaching custom error properties (from #101) which is then easily fixable:

// Given a custom error type with additional properties
function SpecialError(message) {
  this.name = "SpecialError";
  this.message = message;
  this.customInfo = {times: "three"};
  this.otherInfo = {bananas: 4};
}
SpecialError.prototype = Object.create(Error.prototype);

// Additional fields can then be attached to the metadata of a report
Bugsnag.onBeforeNotify(function (notification, error) {
  var customInfo = {};
  var defaultProps = ['message', 'stack', 'name'];
  Object.getOwnPropertyNames(error).forEach(function(propName) {
    if (defaultProps.indexOf(propName) == -1)
      customInfo[propName] = error[propName];
  });
  notification.events[0].metaData['Detailed Error Data'] = customInfo;
});

The metadata of the report then includes the tab "Detailed Error Data" including the non-default fields. There is a similar example in the tests. Later I'd like to revisit this case to potentially do this behavior by default.

Fixes #101

@kattrali kattrali merged commit 906700a into master Jun 5, 2017
@kattrali kattrali deleted the kattrali/before-notify-original-error branch June 5, 2017 15:33
@alexlatchford
Copy link

Great thanks @kattrali!

@kattrali
Copy link
Contributor Author

kattrali commented Jun 5, 2017

No problem! Making a release soon. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom error data is lost during reporting.
2 participants