Repository: firebase/firebase-admin-java
Pull request #546 (2021-05-03 20:47:29)

fix(auth): adds missing EMAIL_NOT_FOUND error code
Catch EMAIL_NOT_FOUND when /accounts:sendOobCode is called for password reset on a user that does not exist.



Patch:
diff --git a/src/main/java/com/google/firebase/auth/AuthErrorCode.java b/src/main/java/com/google/firebase/auth/AuthErrorCode.java
index bea067e..aa28214 100644
--- a/src/main/java/com/google/firebase/auth/AuthErrorCode.java
+++ b/src/main/java/com/google/firebase/auth/AuthErrorCode.java
@@ -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.
    */
diff --git a/src/main/java/com/google/firebase/auth/internal/AuthErrorHandler.java b/src/main/java/com/google/firebase/auth/internal/AuthErrorHandler.java
index e989114..4b9523c 100644
--- a/src/main/java/com/google/firebase/auth/internal/AuthErrorHandler.java
+++ b/src/main/java/com/google/firebase/auth/internal/AuthErrorHandler.java
@@ -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(


Test patch:
diff --git a/src/test/java/com/google/firebase/auth/FirebaseUserManagerTest.java b/src/test/java/com/google/firebase/auth/FirebaseUserManagerTest.java
index 7a25175..dd95ecc 100644
--- a/src/test/java/com/google/firebase/auth/FirebaseUserManagerTest.java
+++ b/src/test/java/com/google/firebase/auth/FirebaseUserManagerTest.java
@@ -1587,6 +1587,27 @@ public class FirebaseUserManagerTest {
     }
   }
 
+  @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, "test@example.com", 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()
@@ -2982,3 +3003,4 @@ public class FirebaseUserManagerTest {
   }
 
 }
+