使用错误的验证码进行身份验证时发生异常 [英] Exception when authenticating with wrong verification code

查看:185
本文介绍了使用错误的验证码进行身份验证时发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Firebase电话身份验证来验证用户帐户.当我尝试使用错误的验证码进行身份验证时,会收到IllegalArgumentException.有什么方法可以解决,而无需使用try catch块?

I'm using Firebase Phone Authentification to verify users accounts. When I try to authenticate with a wrong verification code, I get an IllegalArgumentException. Is there any way to fix that without using try catch blocks?

以下是异常消息:

java.lang.IllegalArgumentException: Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, or temporaryProof.
                                                                 at com.google.android.gms.common.internal.zzbq.checkArgument(Unknown Source)
                                                                 at com.google.firebase.auth.PhoneAuthCredential.<init>(Unknown Source)
                                                                 at com.google.firebase.auth.PhoneAuthProvider.getCredential(Unknown Source)
                                                                 at com.example.myApp.testFragment$3$4.onClick(testFragment.java:316)
                                                                 at android.view.View.performClick(View.java:5197)
                                                                 at android.view.View$PerformClick.run(View.java:20926)
                                                                 at android.os.Handler.handleCallback(Handler.java:739)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                 at android.os.Looper.loop(Looper.java:145)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:5951)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at java.lang.reflect.Method.invoke(Method.java:372)
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

这是我收到错误的行:

PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationCode, inputCode);

我故意在inputCode中使用错误的验证码,希望得到一条错误消息而不是异常.

I'm intentionally using wrong verification code in inputCode and hoping to get an error message instead of the exception.

推荐答案

调用

包装电话号码和验证信息以进行认证.

Wraps phone number and verification information for authentication purposes.

因此,getCredential()无法返回错误消息.相反,如果您提供的验证/凭据信息有问题,它将引发异常.

So getCredential() cannot return an error message. Instead it throws an exception if there is a problem with the verification/credential information you provided.

这篇关于使用错误的验证码进行身份验证时发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆