i just writing a error notification panel in meteor, here i create a client side mongodb, but i cant push Meteor.Error message in to that client side db by throwError function, currently it's shows inside an alert box
我只是在meteor中写了一个错误通知面板,在这里我创建了一个客户端mongodb,但我不能通过throwError函数将Meteor.Error消息推送到该客户端db,目前它显示在一个警告框内
collection/signup.js
收集/ signup.js
signupDB = new Meteor.Collection('signup');
Meteor.methods({
signupSubmit : function(postData) {
var signinEmailExist = signinDB.findOne({
email : postData.email
});
if (postData.email && signinEmailExist)
throw new Meteor.Error(422, "exist in signinDB");
var signupEmailExist = signupDB.findOne({
email : postData.email
});
if (postData.email && signupEmailExist)
throw new Meteor.Error(422, "exist in signupDB"); //
var user = _.extend(_.pick(postData, 'email', 'password'), {
insert_time : new Date().getTime() });
var userId = signupDB.insert(user);
return userId;
}
});
client/error/error.js
客户端/错误/ error.js
errorDB = new Meteor.Collection(null);
throwError = function(data) {
errorDB.insert({data: "in throwError", del: "N"})
}
errorDB.insert({data: "in signup", del: "N"})
code is working anywhere inside client folder
errorDB.insert({data:“in signup”,del:“N”})代码在客户端文件夹内的任何位置工作
here throwError function can't called, but signupSubmit method errors shows in a alert box
这里throwError函数无法调用,但signupSubmit方法错误显示在警告框中
is the problem of publication/subscription like thinks (not wrote for signup db) ?
像think一样出版/订阅的问题(不是为注册数据库写的)?
how i catch and insert Meteor.Error alerts From Meteor.Methods in to a client side db ?
我如何捕获并插入Meteor.Error警报从Meteor.Methods到客户端数据库?
is there any other function like throwError to trap Meteor.Methods errors ?
有没有像throwError这样的其他函数来捕获Meteor.Methods错误?
1 个解决方案
#1
3
How are you calling the method? You need to do something like:
你怎么称呼这个方法?你需要做一些事情:
Meteor.call('signupSubmit', user, function(err) {
errorDB.insert(err);
});
However, you seem to be implementing a custom, insecure authentication system. You shouldn't do this; Meteor has a great, secure built-in Accounts package. All you need to do is (on the client side):
但是,您似乎正在实施自定义,不安全的身份验证系统。你不应该这样做; Meteor有一个很棒的,安全的内置帐户包。您需要做的就是(在客户端):
errors = new Meteor.Collection;
Accounts.createUser({
email: email,
password: password
}, function(err) {
errors.insert(err);
});
The Accounts.createUser
method automatically returns an error if the username/email is duplicated.
如果用户名/电子邮件重复,Accounts.createUser方法会自动返回错误。
#1
3
How are you calling the method? You need to do something like:
你怎么称呼这个方法?你需要做一些事情:
Meteor.call('signupSubmit', user, function(err) {
errorDB.insert(err);
});
However, you seem to be implementing a custom, insecure authentication system. You shouldn't do this; Meteor has a great, secure built-in Accounts package. All you need to do is (on the client side):
但是,您似乎正在实施自定义,不安全的身份验证系统。你不应该这样做; Meteor有一个很棒的,安全的内置帐户包。您需要做的就是(在客户端):
errors = new Meteor.Collection;
Accounts.createUser({
email: email,
password: password
}, function(err) {
errors.insert(err);
});
The Accounts.createUser
method automatically returns an error if the username/email is duplicated.
如果用户名/电子邮件重复,Accounts.createUser方法会自动返回错误。