Created
February 11, 2018 17:59
-
-
Save mihaiserban/686513c632152c4d987aa853026891a9 to your computer and use it in GitHub Desktop.
try catch async await express
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
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