Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Idea: experimental way to add object data to error objects #17

Open
devinrhode2 opened this issue Dec 18, 2012 · 1 comment
Open

Idea: experimental way to add object data to error objects #17

devinrhode2 opened this issue Dec 18, 2012 · 1 comment

Comments

@devinrhode2
Copy link

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.

@niemyjski
Copy link
Collaborator

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.

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

No branches or pull requests

2 participants