Files
HKSingleParty/03_source/api_server.del/src/utils/catchAsync.ts
2025-05-28 09:55:51 +08:00

19 lines
567 B
TypeScript

import { RequestHandler } from 'express';
import { Request, Response, NextFunction } from 'express-serve-static-core';
export interface CustomParamsDictionary {
[key: string]: any;
}
const catchAsync =
(fn: RequestHandler<CustomParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>) =>
(
req: Request<CustomParamsDictionary, any, any, any, Record<string, any>>,
res: Response<any, Record<string, any>, number>,
next: NextFunction
) => {
Promise.resolve(fn(req, res, next)).catch((err) => next(err));
};
export default catchAsync;