Skip to content

Comments

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

Open
abernier wants to merge 7 commits intoironhack-edu:masterfrom
abernier:custom-error-status-message
Open

chore(error-middleware): allow err.message and err.status values to be used#43
abernier wants to merge 7 commits intoironhack-edu:masterfrom
abernier:custom-error-status-message

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)
…-edu#38)

Co-authored-by: sandrabosk <sandraboskovic@hotmail.com>
@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