メテオの公開機能があり、その公開機能でエラーをスローして、サブスクライバーにキャッチさせています。私は Iron-router を使用しており、'waitOn' 関数で出版物を購読しています。なんらかの理由で、パブリケーションからエラーをスローしたときにエラー関数が呼び出されません。その理由はわかりません。助けていただければ幸いです。
'assignmentsByGroup'
サブスクリプション ( to ) と on error 関数 ( onErrorfunction
)を使用したルートは次のとおりです。
this.route('assignmentsList',
{path: '/groups/:groupId',
waitOn: function() {
var onErrorfunction = function(error, result)
{
console.log("onErrorfunction called");
if(error)
{
console.log("Error!");
alert(error.reason);
}
};
return [Meteor.subscribe('assignmentsByGroup', this.params.groupId, onErrorfunction), Meteor.subscribe("groupById", this.params.groupId)];
},
data: function() {
return {
groupId: this.params.groupId
}
}
}
);
そして、ここに私の公開機能があります:
Meteor.publish("assignmentsByGroup", function(groupId)
{
try
{
if(_.contains(Groups.findOne({_id: groupId}).members, this.userId))
{
return Assignments.find({group: groupId});
}
else
{
var errorToThrow = new Meteor.Error(401, "Access denied: you cannot view assignments unless you are a member of this group.");
this.error(errorToThrow);
}
}
catch(err)
{
this.error(err);
}
});