dimdenGD / ultimate-express

The Ultimate Express. Fastest http server with full Express compatibility, based on µWebSockets.
Apache License 2.0
519 stars 15 forks source link

Handle errors in async handlers #14

Closed hillac closed 1 month ago

hillac commented 1 month ago

Any chance you could support handling errors in async handlers? I use express-async-errors with express to avoid the ugly try catch next block in every handler. It would obviously have to be in an option since it's not normal express behavior.

dwbboy commented 1 month ago

router.js 第487行 const out = callback(req, res, next); if(out instanceof Promise) { out.catch(err => { throw err; }); } 改为 callback.constructor.name == "AsyncFunction" ? await callback(req, res, next) : callback(req, res, next);

dimdenGD commented 1 month ago

There's now an option to support async errors: app.set('catch async errors', true) in 1.3.0