Reputation: 493
How can I go about getting the value of the errors I have thrown in a fails insert on a collection or in a method.
Customers.allow({
insert: function(userID, rec) {
console.log(userID === rec.userID);
if (rec.userID === null) {
throw new Meteor.Error(600, "You must be logged in");
};
if (rec.phone.length != 10 ) {
throw new Meteor.Error(601, "Incorect phone format", "Phone must be 10 chars long");
};
if (rec.fax.length != 10 ) {
throw new Meteor.Error(602, "Incorect fax format", "Fax must be 10 chars long");
};
return userID === rec.userID;
}
});
So right now i see the error on the console but say if wanted this display the errors in the template or store it in a reactive session so it can be shown to the user to correct.
like try to to something like this.
Template.form.errors = function () {
// return however you get to those thrown errors
}
Upvotes: 3
Views: 1509
Reputation: 75975
There was a package just released today to help with this : https://github.com/tmeasday/meteor-errors
You would need meteorite to use it : https://github.com/oortcloud/meteorite
Add the package with meteorite:
mrt add errors
(Don't worry you're not adding errors to your meteor besides the command ;)
You can then throw errors in your client js:
Meteor.Errors.throw("Error details");
Then wherever you want to display errors use, in your HTML:
{{>meteorErrors}}
Upvotes: 2