我正在关注文档中的示例:
ref.authWithCustomToken(authToken, function(error, authData) {
if (error) {
console.log("Authentication Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
}
});
如果我将无效令牌传递给 authWithCustomToken(例如 authToken 未定义),它会引发错误,而不是将错误代码传递给回调。换句话说,两者都没有console.log
被执行,但是会抛出这个错误:
First argument must be a valid credential (a string).
将它包装起来try catch
很容易解决问题,但我没有在文档中看到任何提及。这是预期的行为吗?
在我的用例中,令牌是通过 url 传递的,因此未定义的参数是可能的错误情况。