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

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

Description

@devinrhode2

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions