expressjs / response-time

Response time header for node.js
MIT License
477 stars 73 forks source link

Explicitly pass the handler #17

Closed Kikobeats closed 2 months ago

Kikobeats commented 5 years ago

Since the codebase is not returning the next explicitly, when you have an async interface involving this library, the Promise exit early getting the implicit undefined until now returned.

UlisesGascon commented 4 months ago

@carpasse can you have a look?

carpasse commented 3 months ago

I think what @Kikobeats needs can probably be achieved by creating a wrapper around the responseTime middleware:

function responseTimeWrap(opts) {
  var _responseTime = responseTime(opts);

  return function (req, res, next) {
    return new Promise((resolve, reject) => {
      try {
        _responseTime(req, res, resolve);
      } catch (err) {
        reject(err)
      }
    })
    .catch(next)
    .then(next);
  };
}

We should probably wait until Express next Major v5 supports promises natively before implementing such a change.