我正在尝试在我有重复密钥的情况下向客户端发送Meteor.Error。
在客户端上,回调中的“错误”未定义(因为目前,minimongo无法检查唯一键索引)
在服务器上,回调中的“错误”正确引发了一个异常,即存在重复键,因此不会插入。但是,“Meteor.Error”永远不会发送给客户端。
Links.insert({
link: link_to_add,
user_id: this.userId
}, function(error, result) {
if (error != null) {
throw new Meteor.Error(409, 'Link already added');
}
});
我做错了什么?如果有更好的方法,我愿意接受替代方案。
答案 0 :(得分:0)
现在我觉得很明显,但问题是我没有在Meteor.call中捕获错误。
Meteor.call('add_link', {
link: link_to_add,
tag: tag_to_add
}, function(error, result) {
// the error is correctly being captured here
return console.log(error);
});