Skip to content

Fix incorrect handling of rejected promises from Middleware.use() #438

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

Conversation

yazshel
Copy link
Contributor

@yazshel yazshel commented Sep 10, 2018

Currently there are a number of issues in KoaDriver.prototype.prepareMiddlewares() which don't correctly handle rejected Promises returned from KoaMiddlewareInterface-style classes.

This means a user can't make use of error handling when using an async function for KoaMiddlewareInterface.use() implementations. Presently, any throw in an async middleware function is not handled (node logs an "uncaught Promise rejection" error), and the route simply returns the default 404 status.

The simplest way to fix this was to make the KoaDriver middleware wrapper function into an async, and await the completion of the middleware.use() (which works for all use cases of KoaMiddlewareInterface.use() - ie. async, and non-async in both Promise and non-Promise` returning forms.

@yazshel yazshel force-pushed the koa-middleware-error-handling-fix branch from 053975b to c36d1b2 Compare September 11, 2018 04:21
@github-actions
Copy link

github-actions bot commented Feb 8, 2020

Stale pull request message

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants