首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Google Firebase如何捕获特定的Auth异常错误-统一

Google Firebase如何捕获特定的Auth异常错误-统一
EN

Stack Overflow用户
提问于 2018-10-28 21:06:49
回答 1查看 1.4K关注 0票数 1

-How捕获8月异常错误-如果用户/电子邮件存在,统一-How将捕获-统一-Where查找8月异常的列表错误代码-统一

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-28 21:06:49

答案很简单--或者在你想要完成的任务上使用以下功能-

代码语言:javascript
运行
复制
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...."))并完成它与您的代码。

示例

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

统一的8月份异常错误代码列表所有异常都在Firebase.Auth.AuthError类下,您可以在代码编辑器上或在Firebase网站下面的统一- Firebase.Auth -概述(AuthError下)上看到它们。

希望能帮上忙!

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53036083

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档