Skip to content

How to wrap an error object and set custom properties #2

@eguneys

Description

@eguneys

I want to create an error with custom constructor so I can set custom properties like this:

var HTTPError = createCustomError('HTTPError', null, function(code) {
  this.code = code;
});

var error = new HTTPError("You don't have permission', 403);

console.log(error.code);

I also want to wrap this error like this:

var error = new ValidationError("Missing field");
var serverError = new HTTPError("Something went wrong", error);

I can't do both at the same time, either I have to use a custom constructor, or another error object.
How can I create a custom error that wraps an error object, and I can set custom properties on it?

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