Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
eguneys opened this issue Jan 19, 2015 · 0 comments
Open

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

eguneys opened this issue Jan 19, 2015 · 0 comments

Comments

@eguneys
Copy link

eguneys commented Jan 19, 2015

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?

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

No branches or pull requests

1 participant