UNPKG

expresss-ts

Version:

CLI to create an Express TypeScript starter project

18 lines (14 loc) 395 B
import { Request, Response, NextFunction } from "express"; type AsyncFunction = ( req: Request, res: Response, next: NextFunction ) => Promise<any>; const AsyncHandler = (execution: AsyncFunction) => (req: Request, res: Response, next: NextFunction) => { Promise.resolve(execution(req, res, next)).catch((error) => { next(error); }); }; export default AsyncHandler;