Skip to content

Commit 104ab0d

Browse files
fix(auth): adds missing EMAIL_NOT_FOUND error code (#546)
* fix(auth): adds missing EMAIL_NOT_FOUND error code
1 parent 7352a43 commit 104ab0d

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/main/java/com/google/firebase/auth/AuthErrorCode.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ public enum AuthErrorCode {
3636
*/
3737
EMAIL_ALREADY_EXISTS,
3838

39+
/**
40+
* No user record found for the given email, typically raised when
41+
* generating a password reset link using an email for a user that
42+
* is not already registered.
43+
*/
44+
EMAIL_NOT_FOUND,
45+
3946
/**
4047
* The specified ID token is expired.
4148
*/

src/main/java/com/google/firebase/auth/internal/AuthErrorHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ final class AuthErrorHandler extends AbstractHttpErrorHandler<FirebaseAuthExcept
6060
ErrorCode.ALREADY_EXISTS,
6161
"The user with the provided email already exists",
6262
AuthErrorCode.EMAIL_ALREADY_EXISTS))
63+
.put(
64+
"EMAIL_NOT_FOUND",
65+
new AuthError(
66+
ErrorCode.NOT_FOUND,
67+
"No user record found for the given email",
68+
AuthErrorCode.EMAIL_NOT_FOUND))
6369
.put(
6470
"INVALID_DYNAMIC_LINK_DOMAIN",
6571
new AuthError(

src/test/java/com/google/firebase/auth/FirebaseUserManagerTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,27 @@ public void testHttpErrorWithUnknownCode() {
15871587
}
15881588
}
15891589

1590+
@Test
1591+
public void testHttpErrorWithEmailNotFoundCode() {
1592+
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse()
1593+
.setContent("{\"error\": {\"message\": \"EMAIL_NOT_FOUND\"}}")
1594+
.setStatusCode(400);
1595+
FirebaseAuth auth = getRetryDisabledAuth(response);
1596+
FirebaseUserManager userManager = auth.getUserManager();
1597+
try {
1598+
userManager.getEmailActionLink(EmailLinkType.PASSWORD_RESET, "[email protected]", null);
1599+
fail("No exception thrown for HTTP error");
1600+
} catch (FirebaseAuthException e) {
1601+
assertEquals(ErrorCode.NOT_FOUND, e.getErrorCode());
1602+
assertEquals(
1603+
"No user record found for the given email (EMAIL_NOT_FOUND).",
1604+
e.getMessage());
1605+
assertEquals(AuthErrorCode.EMAIL_NOT_FOUND, e.getAuthErrorCode());
1606+
assertTrue(e.getCause() instanceof HttpResponseException);
1607+
assertNotNull(e.getHttpResponse());
1608+
}
1609+
}
1610+
15901611
@Test
15911612
public void testUnexpectedHttpError() {
15921613
MockLowLevelHttpResponse response = new MockLowLevelHttpResponse()
@@ -2982,3 +3003,4 @@ private interface UserManagerOp {
29823003
}
29833004

29843005
}
3006+

0 commit comments

Comments
 (0)