import type { Request, Response, NextFunction, RequestHandler } from "express"; import type { ParamsDictionary, Query } from "express-serve-static-core"; export interface AsyncRequestHandler< P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = Query, Locals extends Record = Record > { ( req: Request, res: Response, next: NextFunction, ): Promise; } export const wrap = < P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = Query, Locals extends Record = Record >(handler: AsyncRequestHandler): RequestHandler => { return (req, res, next) => handler(req, res, next).catch((err) => next(err)); };