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

chore(error-middleware): allow err.message and err.status values to be used #43

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

abernier
Copy link

@abernier abernier commented Sep 19, 2022

next(new Error('boom')) // custom message

// or

err.status = 403 // custom status
next(err)

// or both

const err = new Error('Email already exists')
err.status = 409

next(err)

nevanscott and others added 7 commits February 16, 2022 01:30
ironlauncher with an `n`
… into a utils folder. issue 2: change globally defined �]2;��]1;� variable onto so as not create conflicts with any �]2;��]1;� variable coming from routes. issue 3: rename routes files to add onto file name. issue 4: add cookie-parser onto base express dependencies (ironhack-edu#36)
@itstheandre
Copy link
Collaborator

Interesting, so youre keeping in the error class the status itself?

Nice approach!

Copy link
Collaborator

@itstheandre itstheandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice job!

@abernier
Copy link
Author

abernier commented Sep 19, 2022

thank you, yes it avoids having to:

res.status(403).json({errorMessage: "forbidden"})

👉 which is tedious, and does not take advantage of using the error-middleware, which is here for.


On the contrary, we can just call the error-middleware for that with our error, optionally augmented with status property

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

Successfully merging this pull request may close these issues.

6 participants