You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
437 B
JavaScript

'use strict';
const helpers = module.exports;
helpers.try = function (middleware) {
if (middleware && middleware.constructor && middleware.constructor.name === 'AsyncFunction') {
return async function (req, res, next) {
try {
await middleware(req, res, next);
} catch (err) {
next(err);
}
};
}
return function (req, res, next) {
try {
middleware(req, res, next);
} catch (err) {
next(err);
}
};
};