mongoose-validation-error-transform
Automatically transform Mongoose validation error message(s) to a humanized and readable format, built for CrocodileJS.
Index
Install
npm install --save mongoose-validation-error-transform
You may also want to use mongoose-beautiful-unique-validation too (see this comment)!
Usage
const mongooseValidationErrorTransform = ; mongoose;
If you have a Mongoose schema defined with a required String field full_name
,
and if there is an error with a missing full_name
on a document - then it will
automatically rewrite the message of full_name is required
to
Full name is required
.
If there are multiple validation error messages, such as:
full_name is required
age is not at least (18)
Then it will rewrite the error message to Full name is required, Age is not at least (18)
.
Of course - by modifying the options mentioned above, you can transform the messages however you'd like.
For example, if you'd like to output a <ul>
HTML tag with <li>
for each error (but only of course if there's more than one error):
mongoose;
This would output the following for the previous example:
Full name is requiredAge is not at least (18)
License
MIT © Nick Baugh