如何从Firebase获取错误代码?

编程入门 行业动态 更新时间:2024-10-26 15:28:46
本文介绍了如何从Firebase获取错误代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 Auth.auth().signIn(withEmail: emailTextField.text!, password: passwordTextField.text!) { (user, error) in if error != nil { print(error!) self.warningLabel.isHidden = false; self.passwordTextField.text = ""; } else { print("Log in succesful") self.performSegue(withIdentifier: "welcomeSeg", sender: self) } }

每当我登录或注册用户时,我只会打印通用警告标签,而不是实际问题.我打印了我收到的错误,它太冗长而无法显示给用户.

Whenever I sign in or sign up a user I just print a generic warning label instead of the actual issue. I print the error I receive and it's too verbose to show to the user.

错误域= FIRAuthErrorDomain代码= 17009密码无效或用户没有密码." UserInfo = {NSLocalizedDescription =密码无效或用户没有密码.,error_name = ERROR_WRONG_PASSWORD}

Error Domain=FIRAuthErrorDomain Code=17009 "The password is invalid or the user does not have a password." UserInfo={NSLocalizedDescription=The password is invalid or the user does not have a password., error_name=ERROR_WRONG_PASSWORD}

错误域= FIRAuthErrorDomain代码= 17008电子邮件地址格式错误." UserInfo = {NSLocalizedDescription =电子邮件地址格式错误.,error_name = ERROR_INVALID_EMAIL}

Error Domain=FIRAuthErrorDomain Code=17008 "The email address is badly formatted." UserInfo={NSLocalizedDescription=The email address is badly formatted., error_name=ERROR_INVALID_EMAIL}

有什么方法可以获取错误代码,以便我可以更详细地了解错误消息吗?我仔细阅读了文档,但未提出任何建议.

Is there any way to fetch the error code so I can be more specific with my error messages? I've looked through the documentation but have been unsuccessful in coming up with anything.

推荐答案

我建议根据收到的错误创建一个AuthErrorCode对象(由Firebase SDK提供),并根据需要使用它.如果我没记错的话,AuthErrorCode是一个枚举,其中包含.wrongPassword,.invalidEmail等情况.

I would recommend creating an AuthErrorCode object (provided by the Firebase SDK) from the error you receive and using that as you see fit. If I remember correctly, AuthErrorCode is an enum with cases like .wrongPassword, .invalidEmail, etc.

一个简单的伪代码示例:

A simple pseudocode example:

if error != nil { if let error = AuthErrorCode(rawValue: error?.code) { switch error { case .wrongPassword: // do some stuff with the error code } }

我也感到你的痛苦.我发现在进行更改时,Swift SDK文档会滞后很多.

Also, I feel your pain. I've found that the Swift SDK documentation lags quite a bit when changes come along.

更多推荐

如何从Firebase获取错误代码?

本文发布于:2023-11-26 15:29:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634276.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误代码   Firebase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!