UnhandledPromiseRejectionWarning when async route handler gets rejected
See original GitHub issueImagine you have a rejected promise as a result of processing the request, you get an UnhandledPromiseRejectionWarning. Wouldn’t it be ideal to catch that and send as a normal error, so that the error middleware can take care of that? With some code, imagine you have a get function like
async function get(req, res, next) {
throw new Error('some error');
}
if I set this to handle my request it will throw an UnhandledPromiseRejectionWarning, but I believe in a perfect world this should be wrapped in something like
try {
await get(...);
} catch (error) {
next(error);
}
That way I wouldn’t have to do this for every route I have. Is there any downside to it? Would you guys accept a PR for this?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
UnhandledPromiseRejectionWar...
.catch(error => { throw error}) is a no-op. It results in unhandled rejection in route handler. As explained in this answer, Express doesn't ......
Read more >Handling those unhandled promise rejections with JS async ...
One of your await ed functions fails (i.e. rejects a promise); You get the error. Another possibility is that you know you need...
Read more >Handling Promise rejections in Express.js (Node.js) with ease
Handling Promise rejections in Express.js (Node.js) with ease. Async/await API is a great step towards code readability in Node.js.
Read more >this error originated either by throwing inside of an async ...
.catch(error => { throw error}) is a no-op. It results in unhandled rejection in route handler. As explained in this ...
Read more >Unhandled promise rejection after last middleware · Issue #456
I am using Koa. This is the way I initialize routing-controllers: private init(): void { try { this.server = createKoaServer({ controllers: [__ ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It works perfectly, I guess I missed that one in the configuration. Thank you and sorry for wasting your time! Cheers
https://github.com/kogosoftwarellc/open-api/tree/master/packages/express-openapi#argspromisemode