-
-
Save myndzi/87b61c0cb82f5b26d08a5bf405e2341b 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 Joi = require('joi'); | |
const util = require('util'); | |
const schema = Joi.object().keys({ | |
a: Joi.number().meta('bad a'), | |
b: Joi.number().meta('bad b') | |
}).error(errs => { | |
let obj = { }; | |
errs.forEach(err => { | |
obj[err.path] = Joi.reach(schema, err.path).describe().meta[0]; | |
}); | |
return JSON.stringify(obj); | |
}); | |
const value = { | |
a: 'AAA', | |
b: "BBB" | |
}; | |
const result = Joi.validate(value, schema, { abortEarly: false }); | |
console.log(JSON.parse(result.error.message)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment