@reflet/express
Version:
Well-defined and well-typed express decorators
30 lines (29 loc) • 832 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.wrapAsyncError = exports.wrapAsync = void 0;
const type_guards_1 = require("./type-guards");
/**
* @internal
*/
function wrapAsync(handler) {
if ((0, type_guards_1.isAsyncFunction)(handler)) {
// todo? rename the wrapper to the wrapped function name to have better stack.
return (req, res, next) => {
return handler(req, res, next).catch(next);
};
}
return handler;
}
exports.wrapAsync = wrapAsync;
/**
* @internal
*/
function wrapAsyncError(handler) {
if ((0, type_guards_1.isAsyncFunction)(handler)) {
return (error, req, res, next) => {
return handler(error, req, res, next).catch(next);
};
}
return handler;
}
exports.wrapAsyncError = wrapAsyncError;