According to old docs firebase provide authentication error as firebase error which provides code in it but in new firebase 9.0.2 it will only exception which can be cast to FirebaseAuthException and has getCode but string. Now i want to get all the possible errors in firebase. I have tried but could not find any solution. Ios has handle error section and provides error with code(int) and not in Android. Please help. Thanx in advance
For getting all the possible errors in FirebaseAuth you can do something like this:
private void handleAuthenticationException(@NonNull Exception exception) {
if (exception instanceof FirebaseAuthUserCollisionException) {
if (((FirebaseAuthUserCollisionException) exception).getErrorCode().equals("ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL")) {
//do something...
}
}
// Other relevant exceptions for you...
}
And call this method from your OnFailureListener like this:
firebaseAuth.signInWithCredential(credential).
.addOnSuccessListener(/*Your code here!*/)
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
handleAuthenticationException(exception);
}
);
Please check the FirebaseAuthException documentation for more information.
You may try to Toast the Error by following code at any place that might went wrong.
Toast.makeText(YourActivity.this, ((FirebaseAuthException) task.getException()).getMessage(), Toast.LENGTH_SHORT).show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With