Google Firebase如何捕获特定的Auth异常错误-Unity [英] Google Firebase how to catch specific Auth exception errors - Unity

查看:172
本文介绍了Google Firebase如何捕获特定的Auth异常错误-Unity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-如何捕获Auth异常错误-Unity
-如何捕获用户/电子邮件是否存在-Unity
-在哪里找到Auth异常错误代码列表-Unity

-How to catch Auth exception errors - Unity -How to catch if user/email exists - Unity -Where to find the list of Auth exceptions error code - Unity

*我为Android找到了很多答案,所以我决定最终为Unity编写解决方案。

*I found a lot of answers for Android so I decided to finally write my solution for Unity.

推荐答案

答案很简单-在您要实现的任务上使用以下功能-

The answer is simple- either use the following function on the task you are trying to achieve -

protected bool LogTaskCompletion(Task task, string operation)
{
    bool complete = false;
    if (task.IsCanceled)
    {
        Debug.Log(operation + " canceled.");
    }
    else if (task.IsFaulted)
    {
        Debug.Log(operation + " encounted an error.");
        foreach (Exception exception in task.Exception.Flatten().InnerExceptions)
        {
            string authErrorCode = "";
            Firebase.FirebaseException firebaseEx = exception as Firebase.FirebaseException;
            if (firebaseEx != null)
            {
                authErrorCode = String.Format("AuthError.{0}: ",
                  ((Firebase.Auth.AuthError)firebaseEx.ErrorCode).ToString());
            }
            Debug.Log("number- "+ authErrorCode +"the exception is- "+ exception.ToString());
            string code = ((Firebase.Auth.AuthError)firebaseEx.ErrorCode).ToString();
            Debug.Log(code);
        }
    }
    else if (task.IsCompleted)
    {
        Debug.Log(operation + " completed");
        complete = true;
    }
    return complete;
}

打印输出 Debug.Log(code)是您要查找的异常代码。现在,您可以比较它- if(code.Equals(某些特定例外....))并用您的代码完成。

The printed output Debug.Log(code) is the exception code you are looking for. Now you can compare it - if (code.Equals("some specific exception....")) and complete it with your code.

示例

如何捕获用户/电子邮件是否存在
假设我们使用 CreateUserWithEmailAndPasswordAsync 注册了一个新用户,我们想捕获错误电子邮件地址已在使用中
我们可以使用我的函数来找出我们需要比较的错误代码,它将打印以输出 EmailAlreadyInUse。接下来,我要做的就是检查 if((code).Equals( EmailAlreadyInUse))
-另一种可能的方法是在列表-

How to catch if user/email exists Let's say we sign up a new user with CreateUserWithEmailAndPasswordAsync and we want to catch the error " The email address is already in use" We can use my function to find out what the error code we need to compare and it will print to output "EmailAlreadyInUse". Next all I need to do is to check if ((code).Equals("EmailAlreadyInUse")) -Another possible way is to find the error code in a list-

身份验证例外列表错误代码FOR UNITY
所有例外都在 Firebase类下.Auth.AuthError ,您可以在代码编辑器中,也可以在Firebase网站上的-Unity-Firebase.Auth-概述(在AuthError下)看到它们。

List of Auth exceptions error code FOR UNITY All the exceptions are under class Firebase.Auth.AuthError you can see them either on your code editor, or on Firebase website under - Unity - Firebase.Auth - Overview (under AuthError).

希望有帮助!

这篇关于Google Firebase如何捕获特定的Auth异常错误-Unity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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