How to let express middleware handle errors? #2960
-
|
I'm using export const routeHandler =
(fn: RequestHandler) => (req: Request, res: Response, next: NextFunction) =>
Promise.resolve(fn(req, res, next)).catch(next)Is there a way to achieve the same with this library? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Hello, @jakub-msqt . The error handling workflow is described here: Express Zod API is not a middleware, because it does not call express-zod-api/express-zod-api/src/routing.ts Lines 94 to 96 in 49e871e It is designed to handle errors by the When you throw from So, why won't you place your error handling in a |
Beta Was this translation helpful? Give feedback.
Hello, @jakub-msqt .
The error handling workflow is described here:
https://ez.robintail.cz/v25.5.2/error-handling
Express Zod API is not a middleware, because it does not call
next()here:express-zod-api/express-zod-api/src/routing.ts
Lines 94 to 96 in 49e871e
It is designed to handle errors by the
ResultHandlerattached toEndpointsFactory, so that negative responses would be consistent and match their depiction in the generated documentation.When you throw from
ResultHandlerit ends up inlastResortHandler.So, why won't…