gpt4 book ai didi

javascript - Hook meteor 以捕获所有收集方法错误

转载 作者:行者123 更新时间:2023-11-28 00:25:39 25 4
gpt4 key购买 nike

我有一个向用户显示的错误集合。我想在用户收到错误时插入到此集合中,以便它可以显示在模板中。

我的收藏中有一些会拒绝它的钩子(Hook)。

// only admins can create and update plans
Plans.allow({
insert: function(userId, doc) {
return Roles.userIsInRoles(userId, 'admin');
},
update: function(userId, doc) {
return Roles.userIsInRoles(userId, 'admin');
}
});

// Can only have one active plan currently
Plans.deny({
update: function(userId, doc) {
var now = new Date();
Plans.find({
active: true,
_id: { $in: doc.planIds },
dateStart: { $gt: now },
dateEnd: { $lt: now }
}).count() > 0;
}
});

我的问题是;我可以监听这些事件,并在被拒绝时对客户端和服务器采取特定操作吗?

最佳答案

您可以通过回调函数在您拥有的任何插入/更新/删除上插入集合。

如果您想以服务器方式执行此操作(唱Meteor.methdos/Meteor.call),这就是工作流程。

JS

 //server
Meteor.method({
insertDoc:function(doc){
Plans.insert(doc)
}
})
//Client
Errors = new Mongo.Collection(null) //client side only
Meteor.call('insertDoc',{test:doc},function(err,result){
if(err){
Error.insert({error:err.reason}) //if there is a error lets insert it
}
})
//and the helper to show the error.
Template.example.helpers({
showError:function(){
return Error.find();
}
})

HTML

<template name="example">
<span>Sorry there was an error: {{error}}</span>
</template>

你明白了。

关于javascript - Hook meteor 以捕获所有收集方法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29522297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com