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

查看:31
本文介绍了Google Firebase 如何捕获特定的身份验证异常错误 - 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("some specific exception....")) 并用您的代码完成它.

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 如何捕获特定的身份验证异常错误 - Unity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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