Skip to content

Instantly share code, notes, and snippets.

@jdgo-mars
Created March 8, 2019 07:05
Show Gist options
  • Save jdgo-mars/f76aad961f0a2c3e4366a0d6e442bdcc to your computer and use it in GitHub Desktop.
Save jdgo-mars/f76aad961f0a2c3e4366a0d6e442bdcc to your computer and use it in GitHub Desktop.
// Wrap an async function so we catch any errors that might occur
const wrapAsync = handler => (req, res) =>
handler(req, res)
.then(result => res.json(result))
.catch(error => res.status(500).json({ error: error.message }))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment