lukejagodzinski / meteor-astronomy-validators

https://atmospherejs.com/jagi/astronomy-validators
MIT License
11 stars 13 forks source link

suggestion for .catchValidationException #33

Closed awei01 closed 8 years ago

awei01 commented 8 years ago

Hi,

I thought it might be useful to return the exception if it's not something that .catchValidationException() can handle. Example:

// server
if (!model.validate()) {
    model.throwValidationException();
}
model.save();
return model;

// client
Meteor.call('some-save-method', model, function(error, result) {
    error = model.catchValidationException(error);
    if (error) {
        // do my own handling for a non-validation type exception
        return;
    } 
    // no errors, so do something else
    alert('success');
});

Otherwise, I don't think there's a way to distinguish when the error is handled by model or not.

lukejagodzinski commented 8 years ago

Yes, good suggestion. But I think it would be more reasonable to return true if the error was handled and false otherwise. What do you think?

awei01 commented 8 years ago

seems more logical. updated PR.

lukejagodzinski commented 8 years ago

Ok, thanks! Merging :)