Skip to content

Feature request: wrapper for routes #21

Description

@DJWassink

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions