Skip to content

Instantly share code, notes, and snippets.

@groovecoder
Created September 27, 2019 15:53
Show Gist options
  • Save groovecoder/7607bccad012c9e46dd87f1aa11c20b0 to your computer and use it in GitHub Desktop.
Save groovecoder/7607bccad012c9e46dd87f1aa11c20b0 to your computer and use it in GitHub Desktop.
// Helps handle errors for all async route controllers
// See https://medium.com/@Abazhenov/using-async-await-in-express-with-node-8-b8af872c0016
function asyncMiddleware (fn) {
return (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