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

Promise (rejections) handling #32

Closed
wants to merge 0 commits into from

Conversation

nathanlepori
Copy link

@nathanlepori nathanlepori commented Apr 14, 2022

When using express v5 (currently in beta) or express-async-errors promises returned from a middleware are handled correctly and errors are forwarded to the error handler using next(). Since in newer versions of node promise rejections cause the process to crash, this fix will prevent that from happening.

Solves #31

@nathanlepori
Copy link
Author

I'd like to bump this one. This is a very minor fix. If there's any interest in merging it I can rebase it to the current version and raise a new PR

index.js Outdated
@@ -46,7 +46,7 @@ function unless(middleware, options) {
return next();
}

middleware(req, res, next);
return middleware(req, res, next);
Copy link

@ryus08 ryus08 Jul 29, 2023

Choose a reason for hiding this comment

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

Suggested change
return middleware(req, res, next);
try {
return middleware(req, res, next);
} catch (err) {
return next(err);
}

@ryus08
Copy link

ryus08 commented Jul 29, 2023

This also bit me. express5 is still (a year after the last beta release) still in beta though. So we might also want the try-catch so this works in express4

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