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

Improved Validation Errors #33

Open
michael opened this issue Sep 4, 2011 · 1 comment
Open

Improved Validation Errors #33

michael opened this issue Sep 4, 2011 · 1 comment

Comments

@michael
Copy link
Member

michael commented Sep 4, 2011

By Charles Munat:

Rather than provide an error object with message and property name, why not return as the error object the property's type info itself, merging in a message and the type of failure? For example:

this.properties().each(function(property, key) {

var error = property.toJSON();

...

_.extend(error, { message: 'Property "Name" is required", reason: 'required' })

...

or

_.extend(error, { message: 'Invalid value for property "Date of birth"', reason: 'invalid' })

Then I can tell whether the error is because a required value is missing, or a validation regex failed, and I can access the property name, the validation regex, and the property's meta data and write my own message without having to go looking all over the graph for it. And maybe I'll store required and invalid messages in the meta data and just access them there.

@chasm
Copy link

chasm commented Sep 5, 2011

I tried this and it works like a charm. Very nice. Look out for shallow copies, tho. I'm going to have to go look at how toJSON works, because I've been bitten too many times and I sure don't want to be changing the actual properties...

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