Skip to content

Instantly share code, notes, and snippets.

@ricka
Last active March 24, 2019 18:49
Show Gist options
  • Save ricka/eadac4d9cc6bc3539d8dd39f72a2516d to your computer and use it in GitHub Desktop.
Save ricka/eadac4d9cc6bc3539d8dd39f72a2516d to your computer and use it in GitHub Desktop.
Express Async Wrapper
// Catches all Promisified errors and passes them to next (error) middleware
const asyncWrapper = fn => (...args) => fn(...args).catch(args[2]);
// Also acceptable to Promisify inline
const promiseWrapper = fn => (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