DevSpace/server/util/catchAsync.ts

8 lines
304 B
TypeScript

import {NextFunction, Request, Response} from "express";
export function catchAsync
(fn: (req: Request, res: Response, next: NextFunction) => Promise<Response | NextFunction>){
return async (req: Request, res: Response, next: NextFunction) => {
await fn(req, res, next).catch(next);
};
}