Last active
June 8, 2018 13:09
-
-
Save Abazhenov/ab75a3e02f63b9b47c7b9e399f2572fa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const asyncMiddleware = require('./utils/asyncMiddleware'); | |
router.get('/users/:id', asyncMiddleware(async (req, res, next) => { | |
/* | |
if there is an error thrown in getUserFromDb, asyncMiddleware | |
will pass it to next() and express will handle the error; | |
*/ | |
const user = await getUserFromDb({ id: req.params.id }) | |
res.json(user); | |
})); | |
router.post('/users', asyncMiddleware(async (req, res, next) => { | |
const user = await makeNewUser(req.body); | |
res.json(user) | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment