Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include name of the validation rule in errors? #39

Open
cspotcode opened this issue Feb 28, 2015 · 2 comments
Open

Include name of the validation rule in errors? #39

cspotcode opened this issue Feb 28, 2015 · 2 comments

Comments

@cspotcode
Copy link

I was thinking of using this to validate data and then show friendly errors to the user, so I'd have to map the errors from is-my-json-valid onto some user-friendly messages. I could do this if each errors object contained the name of the rule in question ("minLength", "required", etc) Is that something that could be added to the "verbose" mode?

EDIT added example:

// validator.errors
{ field: 'data.test',
    message: 'has less length than allowed',
    value: 'hello',
    rule: 'minLength' },
{ field: 'data.requiredProp',
    message: 'is required',
    value: undefined,
    rule: 'required' } ]
@danieljuhl
Copy link
Contributor

That would be possible, yes. @mafintosh what do you think? Any reasons not to add the technical validation message?

@danieljuhl
Copy link
Contributor

This could be made as part of #38. It would use schema instead of rule, and it would have some more information, but it should be easy to extract only the rule part of the full schema reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants