Skip to content

fix(auth): adds missing EMAIL_NOT_FOUND error code #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/com/google/firebase/auth/AuthErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public enum AuthErrorCode {
*/
EMAIL_ALREADY_EXISTS,

/**
* No user record found for the given email, typically raised when
* generating a password reset link using an email for a user that
* is not already registered.
*/
EMAIL_NOT_FOUND,

/**
* The specified ID token is expired.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ final class AuthErrorHandler extends AbstractHttpErrorHandler<FirebaseAuthExcept
ErrorCode.ALREADY_EXISTS,
"The user with the provided email already exists",
AuthErrorCode.EMAIL_ALREADY_EXISTS))
.put(
"EMAIL_NOT_FOUND",
new AuthError(
ErrorCode.NOT_FOUND,
"No user record found for the given email",
AuthErrorCode.EMAIL_NOT_FOUND))
.put(
"INVALID_DYNAMIC_LINK_DOMAIN",
new AuthError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,27 @@ public void testHttpErrorWithUnknownCode() {
}
}

@Test
public void testHttpErrorWithEmailNotFoundCode() {
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse()
.setContent("{\"error\": {\"message\": \"EMAIL_NOT_FOUND\"}}")
.setStatusCode(400);
FirebaseAuth auth = getRetryDisabledAuth(response);
FirebaseUserManager userManager = auth.getUserManager();
try {
userManager.getEmailActionLink(EmailLinkType.PASSWORD_RESET, "[email protected]", null);
fail("No exception thrown for HTTP error");
} catch (FirebaseAuthException e) {
assertEquals(ErrorCode.NOT_FOUND, e.getErrorCode());
assertEquals(
"No user record found for the given email (EMAIL_NOT_FOUND).",
e.getMessage());
assertEquals(AuthErrorCode.EMAIL_NOT_FOUND, e.getAuthErrorCode());
assertTrue(e.getCause() instanceof HttpResponseException);
assertNotNull(e.getHttpResponse());
}
}

@Test
public void testUnexpectedHttpError() {
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse()
Expand Down Expand Up @@ -2982,3 +3003,4 @@ private interface UserManagerOp {
}

}