Last active
March 24, 2019 18:49
-
-
Save ricka/eadac4d9cc6bc3539d8dd39f72a2516d to your computer and use it in GitHub Desktop.
Express Async Wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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