You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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...
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:
or
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.
The text was updated successfully, but these errors were encountered: