Skip to content

Instantly share code, notes, and snippets.

@mihaiserban
Created February 11, 2018 17:59
Show Gist options
  • Save mihaiserban/686513c632152c4d987aa853026891a9 to your computer and use it in GitHub Desktop.
Save mihaiserban/686513c632152c4d987aa853026891a9 to your computer and use it in GitHub Desktop.
try catch async await express
router.get('/user/:id', async (req, res, next) => {
try {
const user = await getUserFromDb({ id: req.params.id })
res.json(user);
} catch (e) {
//this will eventually be handled by your error handling middleware
next(e)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment