-
Notifications
You must be signed in to change notification settings - Fork 115
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
Feature Request: Ability to attach custom properties to named errors #66
Comments
Hi! This is implemented already though our factory function, which is our export and interface for creating errors. Here is an example: var err2 = createError(501, 'Route not implemented', { expose: true }) I hope this helps! |
Hi @dougwilson , Thank you for the quick response. I am already aware of the normal createError() function as it is the only method to be able to assign custom properties like that and the one I am currently forced to use. However, that is the exact reason for the feature request - it would be really nice to be able to also assign custom properties when creating "named" errors (without the need to know the error code number). Please reopen the feature request unless you are saying that you do not think this is desirable - in which case I have supporting reasons that it is (ie interface consistency, error code abstraction, etc). |
Hi, there has been multiple requests for the constructor and it is not desirable, no. You are always welcome to publish your own module to npm if that is a feature you want, even if it is just a wrapper to this module. The constructors were only exported for the use of This module provides the factory as the method to construct errors. I know not everyone agrees with the interface, but I'm not going to force you to use this library :) you're always welcome to use a library that offers the API you prefer. That is what npm so great |
duplicate of #29 If you feel strongly about this, please continue the discussion in the issue this is a duplicate of so that the history of conversation is not disjointed between many different issues. I should have directed the other duplicates to do the same, but that is my mistake, so the history in the duplicate is now incomplete. |
Proposal
new createError.[code || name]([msg], [properties]))
Create a new error object with the given message
msg
.The error object inherits from
createError.HttpError
.code
- the status code as a numbername
- the name of the error as a "bumpy case", i.e.NotFound
orInternalServerError
.msg
- (optional) the message of the errorproperties
- (optional) custom properties to attach to the objectThe text was updated successfully, but these errors were encountered: