TraceKit icon indicating copy to clipboard operation
TraceKit copied to clipboard

Idea: experimental way to add object data to error objects

Open devinrhode2 opened this issue 13 years ago • 1 comments

Consider this scenario:

function someOperation() {
  function someOperationFailure(e) {
    //handle failure
  }
  $.ajax({ ... })
  .done(function(resp) {
    if (!resp.userToken) {
      someOperationFailure(new Error('no userToken!' );
    }
}

someOperationFailure gets a message that there's no userToken, but what actually was the response? We could JSON.stringify it into the message, or, I could make a new class that inherits from Error that accepts multiple arguments, and acts intelligently, like adding the data to the error object, and/or maybe adding it onto the e.message.

May or may not be a part of TraceKit, just trying to brainstorm and get feedback.

It would also probably be pretty useful for TraceKit to offer a vanilla normalize function, doing something like var e = TraceKit.normalize(new Error('message')) and then you could just add your data to this normalized error like: e.response = resp in the above scenario.

devinrhode2 avatar Dec 18 '12 22:12 devinrhode2

Currently, I think there is a issue with not providing the original error object as part of the stack trace / or as a parameter.. You might want to parse additional information from the error object. What are your thoughts on this.

niemyjski avatar May 20 '15 13:05 niemyjski