Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase 9.0.2 authentication error codes

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

like image 389
Arjun Gurung Avatar asked Jun 22 '16 08:06

Arjun Gurung


2 Answers

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.

like image 105
Victor Maldonado Avatar answered Sep 28 '22 19:09

Victor Maldonado


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();
like image 30
Loyal Fine Avatar answered Sep 28 '22 20:09

Loyal Fine