Created
May 16, 2018 07:58
-
-
Save simonrenoult/e8eb0934669eb0aadcd83b1ea6b91a65 to your computer and use it in GitHub Desktop.
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
const productSchema = Joi.object().keys({ | |
name: Joi.required(), | |
price: Joi.required(), | |
weight: Joi.required() | |
}); | |
// … | |
app.post("/products", async (req, res) => { | |
const { error } = Joi.validate(req.body, productSchema, { abortEarly: false }); | |
if (error) { | |
const errorMessage = error.details.map(({ message, context }) => { message, context }); | |
return res.status(400).send({ data: errorMessage }); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment