Skip to content
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
15 changes: 2 additions & 13 deletions src/main/java/com/google/firebase/FirebaseException.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ public class FirebaseException extends Exception {
private final ErrorCode errorCode;
private final IncomingHttpResponse httpResponse;

@Deprecated
public FirebaseException(@NonNull String detailMessage) {
this(detailMessage, null);
}

@Deprecated
public FirebaseException(@NonNull String detailMessage, Throwable cause) {
this(ErrorCode.UNKNOWN, detailMessage, cause, null);
}

public FirebaseException(
@NonNull ErrorCode errorCode,
@NonNull String message,
Expand All @@ -64,8 +54,7 @@ public FirebaseException(
*
* @return A Firebase error code.
*/
// TODO: Rename this method to getErrorCode when the child classes are refactored.
public ErrorCode getErrorCodeNew() {
public final ErrorCode getErrorCode() {
return errorCode;
}

Expand All @@ -76,7 +65,7 @@ public ErrorCode getErrorCodeNew() {
* @return An HTTP response or null.
*/
@Nullable
public IncomingHttpResponse getHttpResponse() {
public final IncomingHttpResponse getHttpResponse() {
return httpResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,8 @@ public FirebaseAuthException(
this.errorCode = authErrorCode;
}

public FirebaseAuthException(
@NonNull ErrorCode errorCode, @NonNull String message, Throwable throwable) {
this(errorCode, message, throwable, null, null);
}

public FirebaseAuthException(FirebaseException base) {
this(base.getErrorCodeNew(), base.getMessage(), base.getCause(), base.getHttpResponse(), null);
this(base.getErrorCode(), base.getMessage(), base.getCause(), base.getHttpResponse(), null);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
public final class FirebaseInstanceIdException extends FirebaseException {

FirebaseInstanceIdException(FirebaseException base, String message) {
super(base.getErrorCodeNew(), message, base.getCause(), base.getHttpResponse());
super(base.getErrorCode(), message, base.getCause(), base.getHttpResponse());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected final FirebaseException httpResponseErrorToBaseException(
FirebaseException base = super.httpResponseErrorToBaseException(e, response);
PlatformErrorResponse parsedError = this.parseErrorResponse(e.getContent());

ErrorCode code = base.getErrorCodeNew();
ErrorCode code = base.getErrorCode();
String status = parsedError.getStatus();
if (!Strings.isNullOrEmpty(status)) {
code = Enum.valueOf(ErrorCode.class, parsedError.getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private FirebaseMessagingException(
static FirebaseMessagingException withMessagingErrorCode(
FirebaseException base, @Nullable MessagingErrorCode errorCode) {
return new FirebaseMessagingException(
base.getErrorCodeNew(),
base.getErrorCode(),
base.getMessage(),
base.getCause(),
base.getHttpResponse(),
Expand All @@ -54,7 +54,7 @@ static FirebaseMessagingException withMessagingErrorCode(

static FirebaseMessagingException withCustomMessage(FirebaseException base, String message) {
return new FirebaseMessagingException(
base.getErrorCodeNew(),
base.getErrorCode(),
message,
base.getCause(),
base.getHttpResponse(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class FirebaseProjectManagementException extends FirebaseException
}

FirebaseProjectManagementException(@NonNull FirebaseException base, @NonNull String message) {
super(base.getErrorCodeNew(), message, base.getCause(), base.getHttpResponse());
super(base.getErrorCode(), message, base.getCause(), base.getHttpResponse());
}

FirebaseProjectManagementException(
Expand Down
26 changes: 3 additions & 23 deletions src/test/java/com/google/firebase/FirebaseExceptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testFirebaseExceptionWithoutResponseAndCause() {
null,
null);

assertEquals(ErrorCode.INTERNAL, exception.getErrorCodeNew());
assertEquals(ErrorCode.INTERNAL, exception.getErrorCode());
assertEquals("Test error", exception.getMessage());
assertNull(exception.getHttpResponse());
assertNull(exception.getCause());
Expand All @@ -86,7 +86,7 @@ public void testFirebaseExceptionWithResponse() throws IOException {
null,
response);

assertEquals(ErrorCode.INTERNAL, exception.getErrorCodeNew());
assertEquals(ErrorCode.INTERNAL, exception.getErrorCode());
assertEquals("Test error", exception.getMessage());
assertSame(response, exception.getHttpResponse());
assertNull(exception.getCause());
Expand All @@ -101,32 +101,12 @@ public void testFirebaseExceptionWithCause() {
"Test error",
cause);

assertEquals(ErrorCode.INTERNAL, exception.getErrorCodeNew());
assertEquals(ErrorCode.INTERNAL, exception.getErrorCode());
assertEquals("Test error", exception.getMessage());
assertNull(exception.getHttpResponse());
assertSame(cause, exception.getCause());
}

@Test
public void testFirebaseExceptionLegacyConstructor() {
FirebaseException exception = new FirebaseException("Test error");

assertEquals(ErrorCode.UNKNOWN, exception.getErrorCodeNew());
assertEquals("Test error", exception.getMessage());
assertNull(exception.getHttpResponse());
assertNull(exception.getCause());
}

@Test(expected = IllegalArgumentException.class)
public void testFirebaseExceptionNullDetail() {
new FirebaseException(null);
}

@Test(expected = IllegalArgumentException.class)
public void testFirebaseExceptionEmptyDetail() {
new FirebaseException("");
}

private HttpResponseException createHttpResponseException() throws IOException {
MockLowLevelHttpResponse lowLevelResponse = new MockLowLevelHttpResponse()
.setStatusCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/com/google/firebase/auth/FirebaseAuthIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void testGetNonExistingUser() throws Exception {
assertEquals(
"No user record found for the provided user ID: non.existing",
authException.getMessage());
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
assertNull(authException.getCause());
assertNotNull(authException.getHttpResponse());
assertEquals(AuthErrorCode.USER_NOT_FOUND, authException.getAuthErrorCode());
Expand All @@ -119,7 +119,7 @@ public void testGetNonExistingUserByEmail() throws Exception {
assertEquals(
"No user record found for the provided email: non.existing@definitely.non.existing",
authException.getMessage());
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
assertNull(authException.getCause());
assertNotNull(authException.getHttpResponse());
assertEquals(AuthErrorCode.USER_NOT_FOUND, authException.getAuthErrorCode());
Expand All @@ -137,7 +137,7 @@ public void testUpdateNonExistingUser() throws Exception {
assertEquals(
"No user record found for the given identifier (USER_NOT_FOUND).",
authException.getMessage());
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
assertNotNull(authException.getCause());
assertNotNull(authException.getHttpResponse());
assertEquals(AuthErrorCode.USER_NOT_FOUND, authException.getAuthErrorCode());
Expand All @@ -155,7 +155,7 @@ public void testDeleteNonExistingUser() throws Exception {
assertEquals(
"No user record found for the given identifier (USER_NOT_FOUND).",
authException.getMessage());
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
assertNotNull(authException.getCause());
assertNotNull(authException.getHttpResponse());
assertEquals(AuthErrorCode.USER_NOT_FOUND, authException.getAuthErrorCode());
Expand Down Expand Up @@ -272,7 +272,7 @@ public void testUserLifecycle() throws Exception {
assertEquals(
"No user record found for the provided user ID: " + userRecord.getUid(),
authException.getMessage());
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
assertNull(authException.getCause());
assertNotNull(authException.getHttpResponse());
assertEquals(AuthErrorCode.USER_NOT_FOUND, authException.getAuthErrorCode());
Expand Down Expand Up @@ -724,7 +724,7 @@ private void checkRecreate(String uid) throws Exception {
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof FirebaseAuthException);
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
assertEquals(ErrorCode.ALREADY_EXISTS, authException.getErrorCodeNew());
assertEquals(ErrorCode.ALREADY_EXISTS, authException.getErrorCode());
assertEquals(
"The user with the provided uid already exists (DUPLICATE_LOCAL_ID).",
authException.getMessage());
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/google/firebase/auth/FirebaseAuthTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public void testVerifyIdTokenWithRevocationCheckFailure() {
auth.verifyIdToken("idtoken", true);
fail("No error thrown for revoked ID token");
} catch (FirebaseAuthException e) {
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCodeNew());
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCode());
assertEquals("Firebase id token is revoked.", e.getMessage());
assertNull(e.getCause());
assertNull(e.getHttpResponse());
Expand Down Expand Up @@ -422,7 +422,7 @@ public void testVerifySessionCookieWithRevocationCheckFailure() {
auth.verifySessionCookie("cookie", true);
fail("No error thrown for revoked session cookie");
} catch (FirebaseAuthException e) {
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCodeNew());
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCode());
assertEquals("Firebase session cookie is revoked.", e.getMessage());
assertNull(e.getCause());
assertNull(e.getHttpResponse());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void testMalformedCert() {
tokenVerifier.verifyToken(token);
} catch (FirebaseAuthException e) {
String message = "Error while fetching public key certificates: Could not parse certificate";
assertEquals(ErrorCode.UNKNOWN, e.getErrorCodeNew());
assertEquals(ErrorCode.UNKNOWN, e.getErrorCode());
assertTrue(e.getMessage().startsWith(message));
assertTrue(e.getCause() instanceof GeneralSecurityException);
assertNull(e.getHttpResponse());
Expand All @@ -274,7 +274,7 @@ public LowLevelHttpRequest buildRequest(String method, String url) throws IOExce
Assert.fail("No exception thrown");
} catch (FirebaseAuthException e) {
String message = "Error while fetching public key certificates: Expected error";
assertEquals(ErrorCode.UNKNOWN, e.getErrorCodeNew());
assertEquals(ErrorCode.UNKNOWN, e.getErrorCode());
assertEquals(message, e.getMessage());
assertTrue(e.getCause() instanceof IOException);
assertNull(e.getHttpResponse());
Expand Down Expand Up @@ -317,7 +317,7 @@ public void testMalformedToken() {
String message = "Failed to parse Firebase test token. "
+ "Make sure you passed a string that represents a complete and valid JWT. "
+ "See https://test.doc.url for details on how to retrieve a test token.";
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCodeNew());
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCode());
assertEquals(message, e.getMessage());
assertTrue(e.getCause() instanceof IllegalArgumentException);
assertNull(e.getHttpResponse());
Expand Down Expand Up @@ -454,7 +454,7 @@ private void checkInvalidTokenException(FirebaseAuthException e, String message)
}

private void checkException(FirebaseAuthException e, String message, AuthErrorCode errorCode) {
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCodeNew());
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCode());
assertEquals(message, e.getMessage());
assertNull(e.getCause());
assertNull(e.getHttpResponse());
Expand Down
22 changes: 11 additions & 11 deletions src/test/java/com/google/firebase/auth/FirebaseUserManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void testGetUserWithNotFoundError() throws Exception {
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof FirebaseAuthException);
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
assertEquals(
"No user record found for the provided user ID: testuser", authException.getMessage());
assertNull(authException.getCause());
Expand Down Expand Up @@ -145,7 +145,7 @@ public void testGetUserByEmailWithNotFoundError() throws Exception {
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof FirebaseAuthException);
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
assertEquals(
"No user record found for the provided email: testuser@example.com",
authException.getMessage());
Expand Down Expand Up @@ -174,7 +174,7 @@ public void testGetUserByPhoneNumberWithNotFoundError() throws Exception {
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof FirebaseAuthException);
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
assertEquals(
"No user record found for the provided phone number: +1234567890",
authException.getMessage());
Expand Down Expand Up @@ -588,7 +588,7 @@ public void call(FirebaseAuth auth) throws Exception {
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof FirebaseAuthException);
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
assertEquals(codes.get(code), authException.getErrorCodeNew());
assertEquals(codes.get(code), authException.getErrorCode());
String msg = String.format("Unexpected HTTP response with status: %d\n{}", code);
assertEquals(msg, authException.getMessage());
assertTrue(authException.getCause() instanceof HttpResponseException);
Expand All @@ -608,7 +608,7 @@ public void call(FirebaseAuth auth) throws Exception {
} catch (ExecutionException e) {
assertTrue(e.getCause().toString(), e.getCause() instanceof FirebaseAuthException);
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
assertEquals(
"No user record found for the given identifier (USER_NOT_FOUND).",
authException.getMessage());
Expand All @@ -628,7 +628,7 @@ public void call(FirebaseAuth auth) throws Exception {
} catch (ExecutionException e) {
assertTrue(e.getCause().toString(), e.getCause() instanceof FirebaseAuthException);
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
assertEquals(
"No user record found for the given identifier (USER_NOT_FOUND): Extra details",
authException.getMessage());
Expand All @@ -648,7 +648,7 @@ public void testGetUserMalformedJsonError() throws Exception {
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof FirebaseAuthException);
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
assertEquals(ErrorCode.UNKNOWN, authException.getErrorCodeNew());
assertEquals(ErrorCode.UNKNOWN, authException.getErrorCode());
assertTrue(
authException.getMessage().startsWith("Error while parsing HTTP response: "));
assertTrue(authException.getCause() instanceof IOException);
Expand All @@ -669,7 +669,7 @@ public void testGetUserUnexpectedHttpError() throws Exception {
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof FirebaseAuthException);
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
assertEquals(ErrorCode.INTERNAL, authException.getErrorCodeNew());
assertEquals(ErrorCode.INTERNAL, authException.getErrorCode());
assertEquals("Unexpected HTTP response with status: 500\n{\"not\" json}",
authException.getMessage());
assertTrue(authException.getCause() instanceof HttpResponseException);
Expand Down Expand Up @@ -1224,7 +1224,7 @@ public void testHttpErrorWithCode() {
userManager.getEmailActionLink(EmailLinkType.PASSWORD_RESET, "test@example.com", null);
fail("No exception thrown for HTTP error");
} catch (FirebaseAuthException e) {
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCodeNew());
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCode());
assertEquals(
"The domain of the continue URL is not whitelisted (UNAUTHORIZED_DOMAIN).",
e.getMessage());
Expand All @@ -1246,7 +1246,7 @@ public void testHttpErrorWithUnknownCode() {
userManager.getEmailActionLink(EmailLinkType.PASSWORD_RESET, "test@example.com", null);
fail("No exception thrown for HTTP error");
} catch (FirebaseAuthException e) {
assertEquals(ErrorCode.INTERNAL, e.getErrorCodeNew());
assertEquals(ErrorCode.INTERNAL, e.getErrorCode());
assertEquals("Unexpected HTTP response with status: 500\n" + content, e.getMessage());
assertNull(e.getAuthErrorCode());
assertTrue(e.getCause() instanceof HttpResponseException);
Expand All @@ -1265,7 +1265,7 @@ public void testUnexpectedHttpError() {
userManager.getEmailActionLink(EmailLinkType.PASSWORD_RESET, "test@example.com", null);
fail("No exception thrown for HTTP error");
} catch (FirebaseAuthException e) {
assertEquals(ErrorCode.INTERNAL, e.getErrorCodeNew());
assertEquals(ErrorCode.INTERNAL, e.getErrorCode());
assertEquals("Unexpected HTTP response with status: 500\n{}", e.getMessage());
assertTrue(e.getCause() instanceof HttpResponseException);
assertNotNull(e.getHttpResponse());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void testIAMCryptoSignerHttpError() {
try {
signer.sign("foo".getBytes());
} catch (FirebaseAuthException e) {
assertEquals(ErrorCode.INTERNAL, e.getErrorCodeNew());
assertEquals(ErrorCode.INTERNAL, e.getErrorCode());
assertEquals("Test error", e.getMessage());
assertNotNull(e.getCause());
assertNotNull(e.getHttpResponse());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public void testDeleteInstanceIdTransportError() throws Exception {
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof FirebaseInstanceIdException);
FirebaseInstanceIdException error = (FirebaseInstanceIdException) e.getCause();
assertEquals(ErrorCode.UNKNOWN, error.getErrorCodeNew());
assertEquals(ErrorCode.UNKNOWN, error.getErrorCode());
assertEquals(
"Unknown error while making a remote service call: transport error",
error.getMessage());
Expand Down Expand Up @@ -254,7 +254,7 @@ public void testDeleteInstanceIdInvalidJsonIgnored() throws Exception {
}

private void checkFirebaseInstanceIdException(FirebaseInstanceIdException error, int statusCode) {
assertEquals(ERROR_CODES.get(statusCode), error.getErrorCodeNew());
assertEquals(ERROR_CODES.get(statusCode), error.getErrorCode());
assertEquals(ERROR_MESSAGES.get(statusCode), error.getMessage());
assertTrue(error.getCause() instanceof HttpResponseException);

Expand Down
Loading