meteor / validation-error

Standardized validation error format for Meteor
https://atmospherejs.com/mdg/validation-error
Other
12 stars 4 forks source link

Add type check helper #6

Closed lukejagodzinski closed 8 years ago

lukejagodzinski commented 8 years ago

I would like to propose adding a simple helper for checking type of the error that would be called in the following way:

Meteor.call('methodName', function(err) {
  if (ValidationError.isInstance(err)) {
  }
});

The issue that it solves is a necessity for checking the error property of the error to make sure that it's a validation error. The problem only occurs when error is throw from the server and we catch it on the client. Even if we throw ValidationError we will receive Meteor.Error on the client, because class constructor is not send over the wire. So we have to make additional check.

Feel free to change helper name

lukejagodzinski commented 8 years ago

Maybe better names would be ValidationError.check or ValidationError.is