我一直在clojurescript中使用firebase,并且在这里尝试过建议:
How to catch any Javascript exception in Clojurescript?
到目前为止,我的代码是:
(defn register [email password]
(try
(let [reg (.createUserWithEmailAndPassword (.auth firebase) email password)
_ (.log js/console reg)]
reg)
(catch :default e
(.log js/console "Register Error:" e))))
我怀疑没有发现问题的原因是评估可能会在以后进行,而这只是为了验证这一想法。
我也尝试过:
(defn register [email password]
(try
(.createUserWithEmailAndPassword (.auth firebase) email password)
(catch :default e
(.log js/console "Register Error:" e))))
我称其为:
(apply register ((juxt :email :password) @app-state))
如果我通过了我已经向其注册的电子邮件,则会收到
auth/email-already-in-use
错误,但是我无法捕获它。www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=AIzaSyDzsfz98Y6Pjl1n-uAzfI6GHWKqShFdRI4:1
POST https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=AIzaSyDzsfz98Y6Pjl1n-uAzfI6GHWKqShFdRI4 400 ()
firebase.inc.js:81
Uncaught
Qcode: "auth/email-already-in-use"
message: "The email address is already in use by another account."
__proto__: Error
(anonymous) @ firebase.inc.js:81
我怎么抓到它?还是使用原始javascript处理此问题的唯一方法?
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});
最佳答案
Firebase身份验证是异步的。 Javascript(通常是Clojurescript)的try...catch
在回调中不起作用。调用Firebase处理程序提供的catch
函数,并在发生错误时进行回调,如下所示-这是上面文章中JS代码的字面翻译:
(defn register [email password]
(.. firebase auth (createUserWithEmailAndPassword email password)
(catch (fn [e] (.log js/console "Register Error:" e))))
关于error-handling - 有没有更好的方法来捕获clojurescript中的javascript错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41978754/