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

Handle API errors correctly #86

Merged
merged 6 commits into from
Apr 3, 2018
Merged

Handle API errors correctly #86

merged 6 commits into from
Apr 3, 2018

Conversation

nwalters512
Copy link
Member

This wraps all route handlers with a function that will catch any errors and send them through express.

api/queues.js Outdated
@@ -49,7 +53,7 @@ router.post(
]),
failIfErrors,
],
(req, res, _next) => {
(req, res, next) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a reason this was changed from _next to next?

Copy link
Member Author

Choose a reason for hiding this comment

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

The underscore was used to indicate an unused param, but it's actually used now.

api/queues.js Outdated
queue
.save()
.then(newQueue => res.status(201).json(newQueue))
.catch(next)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this post catching instead of using the wrapper?

Copy link
Member Author

Choose a reason for hiding this comment

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

The wrapper is really only for async stuff, this is using promises directly so it's better to use catch directly.

@nwalters512 nwalters512 merged commit 52ffebb into master Apr 3, 2018
@nwalters512 nwalters512 deleted the catch-api-errors branch April 3, 2018 04:19
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.

2 participants