-How捕获8月异常错误-如果用户/电子邮件存在,统一-How将捕获-统一-Where查找8月异常的列表错误代码-统一
*我为Android找到了很多答案,所以我最终决定为Unity编写我的解决方案。
发布于 2018-10-28 21:06:49
答案很简单--或者在你想要完成的任务上使用以下功能-
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下)上看到它们。
希望能帮上忙!
https://stackoverflow.com/questions/53036083
复制相似问题