How to catch a Firebase Auth specific exceptions

前端 未结 16 2345
慢半拍i
慢半拍i 2020-11-28 04:37

Using Firebase, how do I catch a specific exception and tell the user gracefully about it? E.g :

FirebaseAuthInvalidCredentialsException: The email ad

16条回答
  •  心在旅途
    2020-11-28 05:12

    If you simply want display a message to the user this works. Simple and Elegant:

    if (!task.isSuccessful()) {
        Log.w(TAG, "signInWithEmail:failed", task.getException());
        Toast.makeText(LoginActivity.this, "User Authentication Failed: " + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
    }
    

    It appears that the .getMessage() method converts the exception to a usable format for us already and all we have to do is display that somewhere to the user.

    (This is my first comment, constructive criticism please)

提交回复
热议问题