Express-Torch
Express-Torch copied to clipboard
Feature request: wrapper for routes
Express doesn't really handle async/await that nicely, so either we have to add a try/catch inside an async router function or the error won't be handled by the error fallback, so a lot of times people tend to wrap a handler in an async error catcher, for example:
export const asyncWrapper = (handler: (req: Request, res: Response, next?: NextFunction) => Promise<any>) => (req: Request, res: Response, next?: NextFunction) => {
Promise.resolve(handler(req, res, next)).catch(next);
}
Since we already got a nice route group method, maybe apart from the middleware we can also support a wrapper functionality?
Can you submit a PR with a failing test showing the expecting behavior?