matrix-public-archive/server/lib/express-async-handler.js

15 lines
424 B
JavaScript
Raw Normal View History

2022-02-15 20:33:31 -07:00
'use strict';
2022-02-07 18:55:11 -07:00
// Simple middleware for handling exceptions inside of async express routes and
// passing them to your express error handlers.
//
// via https://github.com/Abazhenov/express-async-handler
const asyncUtil = (fn) =>
function asyncUtilWrap(...args) {
const fnReturn = fn(...args);
const next = args[args.length - 1];
return Promise.resolve(fnReturn).catch(next);
};
module.exports = asyncUtil;