Skip to content

Commit 2524b0e

Browse files
authored
List all error messages, add more helpful descriptions (#801)
1 parent ac71879 commit 2524b0e

File tree

3 files changed

+130
-20
lines changed

3 files changed

+130
-20
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package com.firebase.ui.auth;
2+
3+
import android.support.annotation.RestrictTo;
4+
5+
import com.google.firebase.auth.FirebaseAuthException;
6+
7+
/**
8+
* List of all possible results of {@link FirebaseAuthException#getErrorCode()} and their meanings.
9+
*
10+
* This is a temporary band-aid until we have better documentation and exposure for these
11+
* error codes in the real Firebase Auth SDK.
12+
*/
13+
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
14+
public enum FirebaseAuthError {
15+
16+
ERROR_INVALID_CUSTOM_TOKEN("The custom token format is incorrect. Please check the documentation."),
17+
18+
ERROR_CUSTOM_TOKEN_MISMATCH("Invalid configuration. Ensure your app's SHA1 is correct in the Firebase console."),
19+
20+
ERROR_INVALID_CREDENTIAL("The supplied auth credential is malformed or has expired."),
21+
22+
ERROR_INVALID_EMAIL("The email address is badly formatted."),
23+
24+
ERROR_WRONG_PASSWORD("The password is invalid or the user does not have a password."),
25+
26+
ERROR_USER_MISMATCH("The supplied credentials do not correspond to the previously signed in user."),
27+
28+
ERROR_REQUIRES_RECENT_LOGIN("This operation is sensitive and requires recent authentication. Log in again before retrying this request."),
29+
30+
ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL("An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address."),
31+
32+
ERROR_EMAIL_ALREADY_IN_USE("The email address is already in use by another account."),
33+
34+
ERROR_CREDENTIAL_ALREADY_IN_USE("This credential is already associated with a different user account."),
35+
36+
ERROR_USER_DISABLED( "The user account has been disabled by an administrator."),
37+
38+
ERROR_USER_TOKEN_EXPIRED("The user's credential has expired. The user must sign in again."),
39+
40+
ERROR_USER_NOT_FOUND("There is no user record corresponding to this identifier. The user may have been deleted."),
41+
42+
ERROR_INVALID_USER_TOKEN("The user's credential is no longer valid. The user must sign in again."),
43+
44+
ERROR_OPERATION_NOT_ALLOWED("This operation is not allowed. Enable the sign-in method in the Authentication tab of the Firebase console"),
45+
46+
ERROR_TOO_MANY_REQUESTS("We have blocked all requests from this device due to unusual activity. Try again later."),
47+
48+
ERROR_WEAK_PASSWORD("The given password is too weak, please choose a stronger password."),
49+
50+
ERROR_EXPIRED_ACTION_CODE("The out of band code has expired."),
51+
52+
ERROR_INVALID_ACTION_CODE("The out of band code is invalid. This can happen if the code is malformed, expired, or has already been used."),
53+
54+
ERROR_INVALID_MESSAGE_PAYLOAD("The email template corresponding to this action contains invalid characters in its message. Please fix by going to the Auth email templates section in the Firebase Console."),
55+
56+
ERROR_INVALID_RECIPIENT_EMAIL("The email corresponding to this action failed to send as the provided recipient email address is invalid."),
57+
58+
ERROR_INVALID_SENDER("The email template corresponding to this action contains an invalid sender email or name. Please fix by going to the Auth email templates section in the Firebase Console."),
59+
60+
ERROR_MISSING_EMAIL("An email address must be provided."),
61+
62+
ERROR_MISSING_PASSWORD("A password must be provided."),
63+
64+
ERROR_MISSING_PHONE_NUMBER("To send verification codes, provide a phone number for the recipient."),
65+
66+
ERROR_INVALID_PHONE_NUMBER("The format of the phone number provided is incorrect. Please enter the phone number in a format that can be parsed into E.164 format. E.164 phone numbers are written in the format [+][country code][subscriber number including area code]."),
67+
68+
ERROR_MISSING_VERIFICATION_CODE("The phone auth credential was created with an empty sms verification code"),
69+
70+
ERROR_INVALID_VERIFICATION_CODE("The sms verification code used to create the phone auth credential is invalid. Please resend the verification code sms and be sure use the verification code provided by the user."),
71+
72+
ERROR_MISSING_VERIFICATION_ID("The phone auth credential was created with an empty verification ID"),
73+
74+
ERROR_INVALID_VERIFICATION_ID("The verification ID used to create the phone auth credential is invalid."),
75+
76+
ERROR_RETRY_PHONE_AUTH("An error occurred during authentication using the PhoneAuthCredential. Please retry authentication."),
77+
78+
ERROR_SESSION_EXPIRED("The sms code has expired. Please re-send the verification code to try again."),
79+
80+
ERROR_QUOTA_EXCEEDED("The sms quota for this project has been exceeded."),
81+
82+
ERROR_APP_NOT_AUTHORIZED("This app is not authorized to use Firebase Authentication. Please verify that the correct package name and SHA-1 are configured in the Firebase Console."),
83+
84+
ERROR_API_NOT_AVAILABLE("The API that you are calling is not available on devices without Google Play Services."),
85+
86+
ERROR_UNKNOWN("An unknown error occurred.");
87+
88+
/**
89+
* Get an {@link FirebaseAuthError} from an exception, returning {@link #ERROR_UNKNOWN} as
90+
* a default.
91+
*/
92+
public static FirebaseAuthError fromException(FirebaseAuthException ex) {
93+
try {
94+
return FirebaseAuthError.valueOf(ex.getErrorCode());
95+
} catch (IllegalArgumentException e) {
96+
return FirebaseAuthError.ERROR_UNKNOWN;
97+
}
98+
}
99+
100+
private final String description;
101+
102+
FirebaseAuthError(String description) {
103+
this.description = description;
104+
}
105+
106+
public String getDescription() {
107+
return description;
108+
}
109+
}

auth/src/main/java/com/firebase/ui/auth/ui/phone/PhoneVerificationActivity.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.text.TextUtils;
2828
import android.util.Log;
2929

30+
import com.firebase.ui.auth.FirebaseAuthError;
3031
import com.firebase.ui.auth.IdpResponse;
3132
import com.firebase.ui.auth.R;
3233
import com.firebase.ui.auth.ResultCodes;
@@ -60,11 +61,7 @@ private enum VerificationState {
6061

6162
private static final long SHORT_DELAY_MILLIS = 750;
6263
@VisibleForTesting static final long AUTO_RETRIEVAL_TIMEOUT_MILLIS = 120000;
63-
@VisibleForTesting static final String ERROR_INVALID_PHONE = "ERROR_INVALID_PHONE_NUMBER";
64-
@VisibleForTesting static final String ERROR_INVALID_VERIFICATION = "ERROR_INVALID_VERIFICATION_CODE";
65-
private static final String ERROR_TOO_MANY_REQUESTS = "ERROR_TOO_MANY_REQUESTS";
66-
private static final String ERROR_QUOTA_EXCEEDED = "ERROR_QUOTA_EXCEEDED";
67-
private static final String ERROR_SESSION_EXPIRED = "ERROR_SESSION_EXPIRED";
64+
6865
private static final String KEY_VERIFICATION_PHONE = "KEY_VERIFICATION_PHONE";
6966
private static final String KEY_STATE = "KEY_STATE";
7067

@@ -202,9 +199,10 @@ private void onVerificationFailed(@NonNull FirebaseException ex) {
202199
return;
203200
}
204201
if (ex instanceof FirebaseAuthException) {
205-
FirebaseAuthException firebaseAuthException = (FirebaseAuthException) ex;
206-
switch (firebaseAuthException.getErrorCode()) {
207-
case ERROR_INVALID_PHONE:
202+
FirebaseAuthError error = FirebaseAuthError.fromException((FirebaseAuthException) ex);
203+
204+
switch (error) {
205+
case ERROR_INVALID_PHONE_NUMBER:
208206
verifyPhoneNumberFragment.showError(getString(R.string.invalid_phone_number));
209207
dismissLoadingDialog();
210208
break;
@@ -217,9 +215,9 @@ private void onVerificationFailed(@NonNull FirebaseException ex) {
217215
dismissLoadingDialog();
218216
break;
219217
default:
220-
Log.w(PHONE_VERIFICATION_LOG_TAG, ex.getLocalizedMessage());
218+
Log.w(PHONE_VERIFICATION_LOG_TAG, error.getDescription(), ex);
221219
dismissLoadingDialog();
222-
showAlertDialog(ex.getLocalizedMessage(), null);
220+
showAlertDialog(error.getDescription(), null);
223221
}
224222
} else {
225223
Log.w(PHONE_VERIFICATION_LOG_TAG, ex.getLocalizedMessage());
@@ -331,10 +329,11 @@ public void onFailure(@NonNull Exception e) {
331329
dismissLoadingDialog();
332330
//incorrect confirmation code
333331
if (e instanceof FirebaseAuthInvalidCredentialsException) {
334-
FirebaseAuthInvalidCredentialsException firebaseAuthInvalidCredentialsException
335-
= (FirebaseAuthInvalidCredentialsException) e;
336-
switch (firebaseAuthInvalidCredentialsException.getErrorCode()) {
337-
case ERROR_INVALID_VERIFICATION:
332+
FirebaseAuthError error = FirebaseAuthError.fromException(
333+
(FirebaseAuthInvalidCredentialsException) e);
334+
335+
switch (error) {
336+
case ERROR_INVALID_VERIFICATION_CODE:
338337
showAlertDialog(
339338
getString(R.string.incorrect_code_dialog_body),
340339
new DialogInterface.OnClickListener() {
@@ -357,7 +356,8 @@ public void onClick(DialogInterface dialog, int which) {
357356
});
358357
break;
359358
default:
360-
showAlertDialog(e.getLocalizedMessage(), null);
359+
Log.w(PHONE_VERIFICATION_LOG_TAG, error.getDescription(), e);
360+
showAlertDialog(error.getDescription(), null);
361361
}
362362
} else {
363363
showAlertDialog(e.getLocalizedMessage(), null);

auth/src/test/java/com/firebase/ui/auth/ui/phone/PhoneVerificationActivityTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import com.firebase.ui.auth.AuthUI;
2626
import com.firebase.ui.auth.BuildConfig;
27+
import com.firebase.ui.auth.FirebaseAuthError;
2728
import com.firebase.ui.auth.R;
2829
import com.firebase.ui.auth.testhelpers.AuthHelperShadow;
2930
import com.firebase.ui.auth.testhelpers.AutoCompleteTask;
@@ -58,8 +59,6 @@
5859
import static com.firebase.ui.auth.ui.phone.PhoneTestConstants.YE_COUNTRY_CODE;
5960
import static com.firebase.ui.auth.ui.phone.PhoneTestConstants.YE_RAW_PHONE;
6061
import static com.firebase.ui.auth.ui.phone.PhoneVerificationActivity.AUTO_RETRIEVAL_TIMEOUT_MILLIS;
61-
import static com.firebase.ui.auth.ui.phone.PhoneVerificationActivity.ERROR_INVALID_PHONE;
62-
import static com.firebase.ui.auth.ui.phone.PhoneVerificationActivity.ERROR_INVALID_VERIFICATION;
6362
import static junit.framework.Assert.assertEquals;
6463
import static junit.framework.Assert.assertNotNull;
6564
import static junit.framework.Assert.assertNull;
@@ -173,7 +172,9 @@ public void testVerifyPhoneNumberInvalidPhoneException_showsInlineError() {
173172
PhoneAuthProvider.OnVerificationStateChangedCallbacks onVerificationStateChangedCallbacks
174173
= callbacksArgumentCaptor.getValue();
175174
onVerificationStateChangedCallbacks.onVerificationFailed(
176-
new FirebaseAuthException(ERROR_INVALID_PHONE, "any_message"));
175+
new FirebaseAuthException(
176+
FirebaseAuthError.ERROR_INVALID_PHONE_NUMBER.toString(),
177+
"any_message"));
177178

178179
//was error displayed
179180
assertEquals(mErrorEditText.getText(), mActivity.getString(R.string.invalid_phone_number));
@@ -199,7 +200,7 @@ public void testVerifyPhoneNumberNoMsgException_showsAlertDialog() {
199200
onVerificationStateChangedCallbacks.onVerificationFailed(
200201
new FirebaseAuthException("some_code", "custom_message"));
201202
assertTrue(mActivity.getAlertDialog().isShowing());
202-
assertEquals("custom_message", getAlertDialogMessage());
203+
assertEquals(FirebaseAuthError.ERROR_UNKNOWN.getDescription(), getAlertDialogMessage());
203204
}
204205

205206
@Test
@@ -217,7 +218,7 @@ public void testSubmitCode_badCodeShowsAlertDialog() {
217218
.thenReturn(new AutoCompleteTask<AuthResult>(
218219
null, true,
219220
new FirebaseAuthInvalidCredentialsException(
220-
ERROR_INVALID_VERIFICATION,
221+
FirebaseAuthError.ERROR_INVALID_VERIFICATION_CODE.toString(),
221222
"any_msg")));
222223
testSendConfirmationCode();
223224
SpacedEditText mConfirmationCodeEditText = (SpacedEditText) mActivity.findViewById(R.id.confirmation_code);

0 commit comments

Comments
 (0)