Express: Improve promise/async support for Express 4

Created on 25 Jun 2019  路  1Comment  路  Source: expressjs/express

SUMMARY

I know there is a new and improved Router looming on the horizon for Express 5 (tbd), but it would be nice to see at least basic support for promises/async functions in router handling for current Express (4).

PROPOSAL

What I'd like to see is a pretty basic, non-breaking change:

  • When the router calls a route handler, if it appears to return a "promise-like" object, attach a catch handler to that object that will call the next(error) function if it is triggered.

This would allow the following two handlers to behave identically:

router.use('/', (req, res) => {
    throw new Error('oops');
});

router.use('/', async (req, res) => {
    throw new Error('oops');
});
duplicate router

Most helpful comment

Hi @elliot-nelson ! This has been discussed numerous times, and it was found to be breaking for existing Express 4 apps in the wild, unfortunately, which is why it never landed in Express 4. It has, though, landed in the next router iteration, available for use to test, and in the current Express 5.

https://github.com/expressjs/express/issues/2259#issuecomment-433586394

>All comments

Hi @elliot-nelson ! This has been discussed numerous times, and it was found to be breaking for existing Express 4 apps in the wild, unfortunately, which is why it never landed in Express 4. It has, though, landed in the next router iteration, available for use to test, and in the current Express 5.

https://github.com/expressjs/express/issues/2259#issuecomment-433586394

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sunriselegacy picture Sunriselegacy  路  3Comments

guyisra picture guyisra  路  3Comments

Domiii picture Domiii  路  3Comments

prashantLio picture prashantLio  路  3Comments

ZeddYu picture ZeddYu  路  3Comments