Reputation: 4365
I currently have this code:
if (!task.isSuccessful() && task.getException() != null) {
FirebaseCrash.report(task.getException());
Log.w(TAG, "signInWithCredential", task.getException());
Toast.makeText(SignUp.this, "Authentication failed: " + task.getException().getMessage(),Toast.LENGTH_LONG).show();
}
Sometimes a user gets a FirebaseAuthUserCollisionException
, and I want to detect it in a switch
statement like so:
switch(task.getException()){
case /*I don't know what goes here*/:
//Whatever
}
But as you read, I don't know what to put in the case
statement. What do I put in there? In other words, where is the FirebaseAuthUserCollisionException
located so I can access it? FirebaseAuthUserCollisionException
is just a class so I can't currently do anything with it.
Upvotes: 1
Views: 650
Reputation: 599131
Firebase Authentication exceptions all derive from FirebaseAuthException
, which has a getErrorCode()
method.
So:
if(task.getException() instanceof FirebaseAuthException){
FirebaseAuthException e = (FirebaseAuthException)task.getException();
switch (e.getErrorCode()) {
...
}
}
Upvotes: 2
Reputation: 3260
Try:
if(task.getException() instanceof FirebaseAuthUserCollisionException){
//whatever
}
Upvotes: 0