Meteor 统一响应发布错误

Meteor 统一响应发布错误,meteor,Meteor,假设我有一本相当简单的出版物 Meteor.publish('players', function (guildId) { if (Roles.userIsInRole(this.userId, 'player', guildId)) { return Meteor.users.find({ [`roles.${guildId}`]: 'player' }); } else { this.error(new Meteor.Error(401, "Una

假设我有一本相当简单的出版物

Meteor.publish('players', function (guildId) {
  if (Roles.userIsInRole(this.userId, 'player', guildId)) {
    return Meteor.users.find({
      [`roles.${guildId}`]: 'player'
    });
  } else {
    this.error(new Meteor.Error(401, "Unauthorized"));
  }
});
我有一些这样的。我想知道的是:我能以某种特定的方式回应我发出的代码吗?例如:

OnErrorHooks({
  400: function (err) {
    BlazeLayout.render('Error', {
      content: err.message
    });
  }
});
当然可以:

var挂钩={
400:功能(err){
BlazeLayout.render('错误'{
内容:err.message
});
}
}
handleErrors=函数(错误){
var处理程序挂钩[编号(error.error)];
if(处理程序){
处理程序(错误);
}否则{
log(“没有为错误定义错误处理程序”,error);
}
};
订阅('players',{onStop:handleErrors});
Meteor.subscribe('games',{onStop:handleErrors});
...
如果您的问题是是否有办法将
{onStop:handleerrors}
添加到每个订阅中,那么我猜不会,但当然您也可以为此编写一个方便的函数:

mySubscribe=function(sub){
Meteor.subscribe(sub,{onStop:handleErrors});
};
当然可以:

var挂钩={
400:功能(err){
BlazeLayout.render('错误'{
内容:err.message
});
}
}
handleErrors=函数(错误){
var处理程序挂钩[编号(error.error)];
if(处理程序){
处理程序(错误);
}否则{
log(“没有为错误定义错误处理程序”,error);
}
};
订阅('players',{onStop:handleErrors});
Meteor.subscribe('games',{onStop:handleErrors});
...
如果您的问题是是否有办法将
{onStop:handleerrors}
添加到每个订阅中,那么我猜不会,但当然您也可以为此编写一个方便的函数:

mySubscribe=function(sub){
Meteor.subscribe(sub,{onStop:handleErrors});
};