question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnhandledPromiseRejectionWarning when async route handler gets rejected

See original GitHub issue

Imagine 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:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pjpsoarescommented, Aug 9, 2019

It works perfectly, I guess I missed that one in the configuration. Thank you and sorry for wasting your time! Cheers

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found