コレクションまたはメソッドでの挿入の失敗でスローしたエラーの値を取得するにはどうすればよいですか。
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
}