Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 流星。错误-自定义[原因]_Javascript_Meteor - Fatal编程技术网

Javascript 流星。错误-自定义[原因]

Javascript 流星。错误-自定义[原因],javascript,meteor,Javascript,Meteor,我正在投掷一颗流星。错误原因如下: if (Meteor.isServer) { Accounts.onCreateUser(function(options, user) { ... if (emailAlreadyExist === true) { throw new Meteor.Error(403, "email already registered"); } else { return user } }) } 然后尝试

我正在投掷一颗流星。错误原因如下:

if (Meteor.isServer) {

  Accounts.onCreateUser(function(options, user) {
    ...
    if (emailAlreadyExist === true) {
      throw new Meteor.Error(403, "email already registered");
    } else {
      return user
    }
  })
}
然后尝试向用户显示此错误消息:

if (Meteor.isClient) {
...
    Accounts.createUser({
      email: email,
      password: password
    }, function(error) {
      if (error) {
        // Inform the user that account creation failed
        sAlert.error(error.reason);
      } else {
        // Success.
      }
    });
...
}
但此警报不显示我的自定义流星错误,它总是显示“电子邮件已存在”。
我做错了什么?

我认为这是因为
Accounts.createUser()
抛出了这个错误,这个错误发生在您的
onCreateUser
之前,因此回调会执行。

您是对的!我刚刚从
isServer
中删除了验证,如果已经注册了电子邮件,我仍然会收到错误。这意味着
Accounts.createUser()
内置了自己的验证。事实上,我刚刚查看了文档,上面说“如果现有用户的用户名或电子邮件仅在case中有所不同,createUser将失败。”