如何获取我在集合或方法的失败插入中引发的错误的值。
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;
}
});
所以现在我在控制台上看到了错误,但是说如果想要在模板中显示错误或将其存储在反应会话中,以便可以显示给用户进行更正。
喜欢尝试这样的事情。
Template.form.errors = function () {
// return however you get to those thrown errors
}