import { NextFunction, Request, Response } from 'express'; type Handler = (req: Request, res: Response, next: NextFunction) => Promise | void; /** Wraps an async route/controller handler so a rejected promise reaches errorHandler via next(). */ export function asyncHandler(handler: Handler) { return (req: Request, res: Response, next: NextFunction): void => { Promise.resolve(handler(req, res, next)).catch(next); }; }