ソースコード
using System;
using System.Linq;
using Firebase;
namespace Kogane
{
public static class AggregateExceptionExtensionMethods
{
public static bool IsFirebaseException( this AggregateException self )
{
return self
.Flatten()
.InnerExceptions.Any( x => x is FirebaseException )
;
}
public static FirebaseException GetFirebaseException( this AggregateException self )
{
return self
.Flatten()
.InnerExceptions
.OfType<FirebaseException>()
.First()
;
}
}
}
使用例
using System;
using Firebase.Auth;
using Kogane;
using UnityEngine;
public class Example : MonoBehaviour
{
private async void Start()
{
try
{
var auth = FirebaseAuth.DefaultInstance;
var user = await auth.CreateUserWithEmailAndPasswordAsync( "", "" );
}
catch ( AggregateException e ) when ( e.IsFirebaseException() )
{
var firebaseException = e.GetFirebaseException();
Debug.LogError( firebaseException.GetAuthError() );
}
}
}