11 lines
369 B
TypeScript
11 lines
369 B
TypeScript
|
|
import { NextFunction, Request, RequestHandler, Response } from 'express';
|
||
|
|
|
||
|
|
// Express 4 nie przekazuje odrzuconych Promise do errorHandler — ten wrapper to naprawia
|
||
|
|
export function asyncHandler(
|
||
|
|
fn: (req: Request, res: Response, next: NextFunction) => Promise<unknown>,
|
||
|
|
): RequestHandler {
|
||
|
|
return (req, res, next) => {
|
||
|
|
fn(req, res, next).catch(next);
|
||
|
|
};
|
||
|
|
}
|