Initial commit
This commit is contained in:
10
api/utils/asyncHandler.ts
Normal file
10
api/utils/asyncHandler.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { NextFunction, Request, Response } from 'express'
|
||||
|
||||
export const asyncHandler =
|
||||
<TReq extends Request = Request, TRes extends Response = Response>(
|
||||
fn: (req: TReq, res: TRes, next: NextFunction) => unknown | Promise<unknown>,
|
||||
) =>
|
||||
(req: TReq, res: TRes, next: NextFunction) => {
|
||||
Promise.resolve(fn(req, res, next)).catch(next)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user