每当我登录或注册用户时,我只会打印通用警告标签,而不是实际问题.我打印了我收到的错误,它太冗长而无法显示给用户.
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获取错误代码?
发布评论