How to get failed error type
Hi i'm trying to get the error type failed to validate:
This is what o have when validation fail but i want to know what kind of fail was. like: required or maxlength etc. { value: undefined, msg: 'Invalid value', param: 'lname', location: 'body' }
I need something like this:
{ value: undefined, msg: 'Invalid value', param: 'lname', location: 'body', king: 'required' }
It is impossible for us to detect which option threw the error because validatorjs doesn't give us any kind of information about that e.g. isLength({ min: 10 }). However we can add the generic validator that was unsuccessful e.g. isLength.
If anyone would like to work on this, please raise your hand!
ok. thank you. I fixed I think I use a try catch block.
You added trycatch around check().isLength...?
As a suggestion, you can use withMessage to send error codes back to your frontend application, e.g. check('name').isAlpha().withMessage('IS_ALPHA').
It may be a bit cumbersome, but allows for greater flexibility, in my opinion.
Closing as it's been ~2 years since the last activity
Please open a new issue if needed.