Skip to content

Instantly share code, notes, and snippets.

@ChaseH88
Created February 11, 2021 22:34
Show Gist options
  • Select an option

  • Save ChaseH88/265901129e2877fb4952d3ef9ad15cb5 to your computer and use it in GitHub Desktop.

Select an option

Save ChaseH88/265901129e2877fb4952d3ef9ad15cb5 to your computer and use it in GitHub Desktop.
import { Request, Response, RequestHandler, NextFunction } from 'express';
export const asyncHandler = (
fn: (req: Request, res: Response, next: NextFunction) => void
): RequestHandler => (req, res, next) => {
Promise.resolve(fn(req, res, next)).catch(next);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment