Skip to content

Helper for wrapped errors #2

@meaku

Description

@meaku

Sometime it's useful to catch some known errors and convert them to erroz-errors. Unfortunately those errorz-erros have the stacktrace of erroz-creation. It might be helpful to add an option to pass an original error when creating an erroz-error instance to append the original error.

Something like:

var ParseError = erroz({
  statusCode: 400,
  status: "fail",
  name: "ParseError",
  code: "parse-error",
  template "Could not parse %what"
});

try{ 
  JSON.parse("xaz--");
}
catch(err) {
   //pass original err as second argument (optional)
   errozErr = new ParseError({ what: "ever" }, err); 

   console.log(errozErr.stack) //would equal err.stack    
 }

Although it seems convenient it's also confusing as the stack is not pointing to the real "throw" . Maybe it's possible to merge the stacks or introduce a second originalStack attribute.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions