lukejagodzinski / meteor-astronomy-validators

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

Is there way to add errors manually? #10

Open ribbedcrown opened 9 years ago

ribbedcrown commented 9 years ago

It`ll be useful for example for Meteor Accounts error displaying:

Accounts.forgotPassword({ email: form.get('email') }, err => {
  if (err && typeof err.reason === 'string') {
    const reason = err.reason;

    if (reason.indexOf('User not found') !== -1) {
      // adding error manually
    }
      // ...
  }
});

where form is Astro.Class instance.

Maybe something similar to Simple Schema`s validationContext.addInvalidKeys(errors).

P.S. Great work, many thanks!

lukejagodzinski commented 9 years ago

If don't know if in your case is it needed however it may be good feature to implement. I will probably add it in the near future. However, right now you can do it using some internal API.

form._errors.set('fieldName', 'Error message');

Right now all error messages are related with some field name. However I will be working on implementing field errors and document errors. Where document errors will be related with entire document, not particular field.

ribbedcrown commented 9 years ago

Thank you, @jagi, this is what I need! Document errors looks useful for work with error summaries. It'll be cool feature.