express-validator-errors
Error json serializer for consistent errors when using express-validator
Combines errors from different sources:
- errors in serializer function argument
- errors in req.body.errors
- errors in req.validationErrors()
Usage Examples
Data Validation
errors.addToReq
- add your own errors to to express-validator's _validationErrors
without mixing in new validators
errors.serialize
- outputs all known validation errors
var errors = var { if !reqbodyobjects errors req return reqlength == 0} var { if // ... happiness else res } // example input =>// { objects: [{}] } // outputs =>// { // "errors": [// {// "param": "objects.0.title",// "msg": "Title is required"// }// ]// }
Error Handling
errors.serialize
- outputs all known validation errors and the specific errors you ask it to output. Options are:
- Null (in which case, errors on req are serialized)
- Single error
- Array of errors
- Single Error object
var errors = var {