-
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
How to send the message in different structure ? #103
Comments
Adding custom properties to errors is only supported currently when using One property you can't set in the object is the const error =
createError(404, {
field: "email",
message: "User not found"
})
console.log(error.name) // NotFoundError
console.log(error.field) // email
console.log(error.message) // User not found
const stillNotFound = createError(404, {
status: 500, // setting status here will be ignored
field: "email",
message: "User not found"
})
console.log(stillNotFound.status) // 404 The shortcut method forms are just constructors that accept a message arg and nothing else. They're used to power the createError interface and allow you to do things like: const error =
createError(404, {
field: "email",
message: "User not found"
})
console.log(error instanceof createError.NotFound) // true |
thanks, but i usually prefer using a shortcut method to make my code more readable. For instance, instead of using a status code such as 404, I prefer to use "NotFound". |
I agree this is likely what users expect. |
instead of :
if (!foundUser) return next(createError.NotFound("User not found"));
i want to send an object like this :
The text was updated successfully, but these errors were encountered: