Skip to content

Commit b785e02

Browse files
authored
Renamed getErrorCodeNew() to getErrorCode() (#379)
* Minor code and test cleanup * Renamed getErrorCodeNew() to getErrorCode() in FirebaseException * Fixing checkstyle error
1 parent eb32c9c commit b785e02

19 files changed

+74
-110
lines changed

src/main/java/com/google/firebase/FirebaseException.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ public class FirebaseException extends Exception {
3131
private final ErrorCode errorCode;
3232
private final IncomingHttpResponse httpResponse;
3333

34-
@Deprecated
35-
public FirebaseException(@NonNull String detailMessage) {
36-
this(detailMessage, null);
37-
}
38-
39-
@Deprecated
40-
public FirebaseException(@NonNull String detailMessage, Throwable cause) {
41-
this(ErrorCode.UNKNOWN, detailMessage, cause, null);
42-
}
43-
4434
public FirebaseException(
4535
@NonNull ErrorCode errorCode,
4636
@NonNull String message,
@@ -64,8 +54,7 @@ public FirebaseException(
6454
*
6555
* @return A Firebase error code.
6656
*/
67-
// TODO: Rename this method to getErrorCode when the child classes are refactored.
68-
public ErrorCode getErrorCodeNew() {
57+
public final ErrorCode getErrorCode() {
6958
return errorCode;
7059
}
7160

@@ -76,7 +65,7 @@ public ErrorCode getErrorCodeNew() {
7665
* @return An HTTP response or null.
7766
*/
7867
@Nullable
79-
public IncomingHttpResponse getHttpResponse() {
68+
public final IncomingHttpResponse getHttpResponse() {
8069
return httpResponse;
8170
}
8271
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,8 @@ public FirebaseAuthException(
4040
this.errorCode = authErrorCode;
4141
}
4242

43-
public FirebaseAuthException(
44-
@NonNull ErrorCode errorCode, @NonNull String message, Throwable throwable) {
45-
this(errorCode, message, throwable, null, null);
46-
}
47-
4843
public FirebaseAuthException(FirebaseException base) {
49-
this(base.getErrorCodeNew(), base.getMessage(), base.getCause(), base.getHttpResponse(), null);
44+
this(base.getErrorCode(), base.getMessage(), base.getCause(), base.getHttpResponse(), null);
5045
}
5146

5247
@Nullable

src/main/java/com/google/firebase/iid/FirebaseInstanceIdException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
public final class FirebaseInstanceIdException extends FirebaseException {
2525

2626
FirebaseInstanceIdException(FirebaseException base, String message) {
27-
super(base.getErrorCodeNew(), message, base.getCause(), base.getHttpResponse());
27+
super(base.getErrorCode(), message, base.getCause(), base.getHttpResponse());
2828
}
2929
}

src/main/java/com/google/firebase/internal/AbstractPlatformErrorHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected final FirebaseException httpResponseErrorToBaseException(
4646
FirebaseException base = super.httpResponseErrorToBaseException(e, response);
4747
PlatformErrorResponse parsedError = this.parseErrorResponse(e.getContent());
4848

49-
ErrorCode code = base.getErrorCodeNew();
49+
ErrorCode code = base.getErrorCode();
5050
String status = parsedError.getStatus();
5151
if (!Strings.isNullOrEmpty(status)) {
5252
code = Enum.valueOf(ErrorCode.class, parsedError.getStatus());

src/main/java/com/google/firebase/messaging/FirebaseMessagingException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private FirebaseMessagingException(
4545
static FirebaseMessagingException withMessagingErrorCode(
4646
FirebaseException base, @Nullable MessagingErrorCode errorCode) {
4747
return new FirebaseMessagingException(
48-
base.getErrorCodeNew(),
48+
base.getErrorCode(),
4949
base.getMessage(),
5050
base.getCause(),
5151
base.getHttpResponse(),
@@ -54,7 +54,7 @@ static FirebaseMessagingException withMessagingErrorCode(
5454

5555
static FirebaseMessagingException withCustomMessage(FirebaseException base, String message) {
5656
return new FirebaseMessagingException(
57-
base.getErrorCodeNew(),
57+
base.getErrorCode(),
5858
message,
5959
base.getCause(),
6060
base.getHttpResponse(),

src/main/java/com/google/firebase/projectmanagement/FirebaseProjectManagementException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public final class FirebaseProjectManagementException extends FirebaseException
3131
}
3232

3333
FirebaseProjectManagementException(@NonNull FirebaseException base, @NonNull String message) {
34-
super(base.getErrorCodeNew(), message, base.getCause(), base.getHttpResponse());
34+
super(base.getErrorCode(), message, base.getCause(), base.getHttpResponse());
3535
}
3636

3737
FirebaseProjectManagementException(

src/test/java/com/google/firebase/FirebaseExceptionTest.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void testFirebaseExceptionWithoutResponseAndCause() {
6767
null,
6868
null);
6969

70-
assertEquals(ErrorCode.INTERNAL, exception.getErrorCodeNew());
70+
assertEquals(ErrorCode.INTERNAL, exception.getErrorCode());
7171
assertEquals("Test error", exception.getMessage());
7272
assertNull(exception.getHttpResponse());
7373
assertNull(exception.getCause());
@@ -86,7 +86,7 @@ public void testFirebaseExceptionWithResponse() throws IOException {
8686
null,
8787
response);
8888

89-
assertEquals(ErrorCode.INTERNAL, exception.getErrorCodeNew());
89+
assertEquals(ErrorCode.INTERNAL, exception.getErrorCode());
9090
assertEquals("Test error", exception.getMessage());
9191
assertSame(response, exception.getHttpResponse());
9292
assertNull(exception.getCause());
@@ -101,32 +101,12 @@ public void testFirebaseExceptionWithCause() {
101101
"Test error",
102102
cause);
103103

104-
assertEquals(ErrorCode.INTERNAL, exception.getErrorCodeNew());
104+
assertEquals(ErrorCode.INTERNAL, exception.getErrorCode());
105105
assertEquals("Test error", exception.getMessage());
106106
assertNull(exception.getHttpResponse());
107107
assertSame(cause, exception.getCause());
108108
}
109109

110-
@Test
111-
public void testFirebaseExceptionLegacyConstructor() {
112-
FirebaseException exception = new FirebaseException("Test error");
113-
114-
assertEquals(ErrorCode.UNKNOWN, exception.getErrorCodeNew());
115-
assertEquals("Test error", exception.getMessage());
116-
assertNull(exception.getHttpResponse());
117-
assertNull(exception.getCause());
118-
}
119-
120-
@Test(expected = IllegalArgumentException.class)
121-
public void testFirebaseExceptionNullDetail() {
122-
new FirebaseException(null);
123-
}
124-
125-
@Test(expected = IllegalArgumentException.class)
126-
public void testFirebaseExceptionEmptyDetail() {
127-
new FirebaseException("");
128-
}
129-
130110
private HttpResponseException createHttpResponseException() throws IOException {
131111
MockLowLevelHttpResponse lowLevelResponse = new MockLowLevelHttpResponse()
132112
.setStatusCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void testGetNonExistingUser() throws Exception {
101101
assertEquals(
102102
"No user record found for the provided user ID: non.existing",
103103
authException.getMessage());
104-
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
104+
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
105105
assertNull(authException.getCause());
106106
assertNotNull(authException.getHttpResponse());
107107
assertEquals(AuthErrorCode.USER_NOT_FOUND, authException.getAuthErrorCode());
@@ -119,7 +119,7 @@ public void testGetNonExistingUserByEmail() throws Exception {
119119
assertEquals(
120120
"No user record found for the provided email: [email protected]",
121121
authException.getMessage());
122-
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
122+
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
123123
assertNull(authException.getCause());
124124
assertNotNull(authException.getHttpResponse());
125125
assertEquals(AuthErrorCode.USER_NOT_FOUND, authException.getAuthErrorCode());
@@ -137,7 +137,7 @@ public void testUpdateNonExistingUser() throws Exception {
137137
assertEquals(
138138
"No user record found for the given identifier (USER_NOT_FOUND).",
139139
authException.getMessage());
140-
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
140+
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
141141
assertNotNull(authException.getCause());
142142
assertNotNull(authException.getHttpResponse());
143143
assertEquals(AuthErrorCode.USER_NOT_FOUND, authException.getAuthErrorCode());
@@ -155,7 +155,7 @@ public void testDeleteNonExistingUser() throws Exception {
155155
assertEquals(
156156
"No user record found for the given identifier (USER_NOT_FOUND).",
157157
authException.getMessage());
158-
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
158+
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
159159
assertNotNull(authException.getCause());
160160
assertNotNull(authException.getHttpResponse());
161161
assertEquals(AuthErrorCode.USER_NOT_FOUND, authException.getAuthErrorCode());
@@ -272,7 +272,7 @@ public void testUserLifecycle() throws Exception {
272272
assertEquals(
273273
"No user record found for the provided user ID: " + userRecord.getUid(),
274274
authException.getMessage());
275-
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
275+
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
276276
assertNull(authException.getCause());
277277
assertNotNull(authException.getHttpResponse());
278278
assertEquals(AuthErrorCode.USER_NOT_FOUND, authException.getAuthErrorCode());
@@ -724,7 +724,7 @@ private void checkRecreate(String uid) throws Exception {
724724
} catch (ExecutionException e) {
725725
assertTrue(e.getCause() instanceof FirebaseAuthException);
726726
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
727-
assertEquals(ErrorCode.ALREADY_EXISTS, authException.getErrorCodeNew());
727+
assertEquals(ErrorCode.ALREADY_EXISTS, authException.getErrorCode());
728728
assertEquals(
729729
"The user with the provided uid already exists (DUPLICATE_LOCAL_ID).",
730730
authException.getMessage());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public void testVerifyIdTokenWithRevocationCheckFailure() {
255255
auth.verifyIdToken("idtoken", true);
256256
fail("No error thrown for revoked ID token");
257257
} catch (FirebaseAuthException e) {
258-
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCodeNew());
258+
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCode());
259259
assertEquals("Firebase id token is revoked.", e.getMessage());
260260
assertNull(e.getCause());
261261
assertNull(e.getHttpResponse());
@@ -422,7 +422,7 @@ public void testVerifySessionCookieWithRevocationCheckFailure() {
422422
auth.verifySessionCookie("cookie", true);
423423
fail("No error thrown for revoked session cookie");
424424
} catch (FirebaseAuthException e) {
425-
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCodeNew());
425+
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCode());
426426
assertEquals("Firebase session cookie is revoked.", e.getMessage());
427427
assertNull(e.getCause());
428428
assertNull(e.getHttpResponse());

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public void testMalformedCert() {
249249
tokenVerifier.verifyToken(token);
250250
} catch (FirebaseAuthException e) {
251251
String message = "Error while fetching public key certificates: Could not parse certificate";
252-
assertEquals(ErrorCode.UNKNOWN, e.getErrorCodeNew());
252+
assertEquals(ErrorCode.UNKNOWN, e.getErrorCode());
253253
assertTrue(e.getMessage().startsWith(message));
254254
assertTrue(e.getCause() instanceof GeneralSecurityException);
255255
assertNull(e.getHttpResponse());
@@ -274,7 +274,7 @@ public LowLevelHttpRequest buildRequest(String method, String url) throws IOExce
274274
Assert.fail("No exception thrown");
275275
} catch (FirebaseAuthException e) {
276276
String message = "Error while fetching public key certificates: Expected error";
277-
assertEquals(ErrorCode.UNKNOWN, e.getErrorCodeNew());
277+
assertEquals(ErrorCode.UNKNOWN, e.getErrorCode());
278278
assertEquals(message, e.getMessage());
279279
assertTrue(e.getCause() instanceof IOException);
280280
assertNull(e.getHttpResponse());
@@ -317,7 +317,7 @@ public void testMalformedToken() {
317317
String message = "Failed to parse Firebase test token. "
318318
+ "Make sure you passed a string that represents a complete and valid JWT. "
319319
+ "See https://test.doc.url for details on how to retrieve a test token.";
320-
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCodeNew());
320+
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCode());
321321
assertEquals(message, e.getMessage());
322322
assertTrue(e.getCause() instanceof IllegalArgumentException);
323323
assertNull(e.getHttpResponse());
@@ -454,7 +454,7 @@ private void checkInvalidTokenException(FirebaseAuthException e, String message)
454454
}
455455

456456
private void checkException(FirebaseAuthException e, String message, AuthErrorCode errorCode) {
457-
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCodeNew());
457+
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCode());
458458
assertEquals(message, e.getMessage());
459459
assertNull(e.getCause());
460460
assertNull(e.getHttpResponse());

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void testGetUserWithNotFoundError() throws Exception {
117117
} catch (ExecutionException e) {
118118
assertTrue(e.getCause() instanceof FirebaseAuthException);
119119
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
120-
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
120+
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
121121
assertEquals(
122122
"No user record found for the provided user ID: testuser", authException.getMessage());
123123
assertNull(authException.getCause());
@@ -145,7 +145,7 @@ public void testGetUserByEmailWithNotFoundError() throws Exception {
145145
} catch (ExecutionException e) {
146146
assertTrue(e.getCause() instanceof FirebaseAuthException);
147147
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
148-
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
148+
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
149149
assertEquals(
150150
"No user record found for the provided email: [email protected]",
151151
authException.getMessage());
@@ -174,7 +174,7 @@ public void testGetUserByPhoneNumberWithNotFoundError() throws Exception {
174174
} catch (ExecutionException e) {
175175
assertTrue(e.getCause() instanceof FirebaseAuthException);
176176
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
177-
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
177+
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
178178
assertEquals(
179179
"No user record found for the provided phone number: +1234567890",
180180
authException.getMessage());
@@ -588,7 +588,7 @@ public void call(FirebaseAuth auth) throws Exception {
588588
} catch (ExecutionException e) {
589589
assertTrue(e.getCause() instanceof FirebaseAuthException);
590590
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
591-
assertEquals(codes.get(code), authException.getErrorCodeNew());
591+
assertEquals(codes.get(code), authException.getErrorCode());
592592
String msg = String.format("Unexpected HTTP response with status: %d\n{}", code);
593593
assertEquals(msg, authException.getMessage());
594594
assertTrue(authException.getCause() instanceof HttpResponseException);
@@ -608,7 +608,7 @@ public void call(FirebaseAuth auth) throws Exception {
608608
} catch (ExecutionException e) {
609609
assertTrue(e.getCause().toString(), e.getCause() instanceof FirebaseAuthException);
610610
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
611-
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
611+
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
612612
assertEquals(
613613
"No user record found for the given identifier (USER_NOT_FOUND).",
614614
authException.getMessage());
@@ -628,7 +628,7 @@ public void call(FirebaseAuth auth) throws Exception {
628628
} catch (ExecutionException e) {
629629
assertTrue(e.getCause().toString(), e.getCause() instanceof FirebaseAuthException);
630630
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
631-
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCodeNew());
631+
assertEquals(ErrorCode.NOT_FOUND, authException.getErrorCode());
632632
assertEquals(
633633
"No user record found for the given identifier (USER_NOT_FOUND): Extra details",
634634
authException.getMessage());
@@ -648,7 +648,7 @@ public void testGetUserMalformedJsonError() throws Exception {
648648
} catch (ExecutionException e) {
649649
assertTrue(e.getCause() instanceof FirebaseAuthException);
650650
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
651-
assertEquals(ErrorCode.UNKNOWN, authException.getErrorCodeNew());
651+
assertEquals(ErrorCode.UNKNOWN, authException.getErrorCode());
652652
assertTrue(
653653
authException.getMessage().startsWith("Error while parsing HTTP response: "));
654654
assertTrue(authException.getCause() instanceof IOException);
@@ -669,7 +669,7 @@ public void testGetUserUnexpectedHttpError() throws Exception {
669669
} catch (ExecutionException e) {
670670
assertTrue(e.getCause() instanceof FirebaseAuthException);
671671
FirebaseAuthException authException = (FirebaseAuthException) e.getCause();
672-
assertEquals(ErrorCode.INTERNAL, authException.getErrorCodeNew());
672+
assertEquals(ErrorCode.INTERNAL, authException.getErrorCode());
673673
assertEquals("Unexpected HTTP response with status: 500\n{\"not\" json}",
674674
authException.getMessage());
675675
assertTrue(authException.getCause() instanceof HttpResponseException);
@@ -1224,7 +1224,7 @@ public void testHttpErrorWithCode() {
12241224
userManager.getEmailActionLink(EmailLinkType.PASSWORD_RESET, "[email protected]", null);
12251225
fail("No exception thrown for HTTP error");
12261226
} catch (FirebaseAuthException e) {
1227-
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCodeNew());
1227+
assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCode());
12281228
assertEquals(
12291229
"The domain of the continue URL is not whitelisted (UNAUTHORIZED_DOMAIN).",
12301230
e.getMessage());
@@ -1246,7 +1246,7 @@ public void testHttpErrorWithUnknownCode() {
12461246
userManager.getEmailActionLink(EmailLinkType.PASSWORD_RESET, "[email protected]", null);
12471247
fail("No exception thrown for HTTP error");
12481248
} catch (FirebaseAuthException e) {
1249-
assertEquals(ErrorCode.INTERNAL, e.getErrorCodeNew());
1249+
assertEquals(ErrorCode.INTERNAL, e.getErrorCode());
12501250
assertEquals("Unexpected HTTP response with status: 500\n" + content, e.getMessage());
12511251
assertNull(e.getAuthErrorCode());
12521252
assertTrue(e.getCause() instanceof HttpResponseException);
@@ -1265,7 +1265,7 @@ public void testUnexpectedHttpError() {
12651265
userManager.getEmailActionLink(EmailLinkType.PASSWORD_RESET, "[email protected]", null);
12661266
fail("No exception thrown for HTTP error");
12671267
} catch (FirebaseAuthException e) {
1268-
assertEquals(ErrorCode.INTERNAL, e.getErrorCodeNew());
1268+
assertEquals(ErrorCode.INTERNAL, e.getErrorCode());
12691269
assertEquals("Unexpected HTTP response with status: 500\n{}", e.getMessage());
12701270
assertTrue(e.getCause() instanceof HttpResponseException);
12711271
assertNotNull(e.getHttpResponse());

src/test/java/com/google/firebase/auth/internal/CryptoSignersTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void testIAMCryptoSignerHttpError() {
104104
try {
105105
signer.sign("foo".getBytes());
106106
} catch (FirebaseAuthException e) {
107-
assertEquals(ErrorCode.INTERNAL, e.getErrorCodeNew());
107+
assertEquals(ErrorCode.INTERNAL, e.getErrorCode());
108108
assertEquals("Test error", e.getMessage());
109109
assertNotNull(e.getCause());
110110
assertNotNull(e.getHttpResponse());

src/test/java/com/google/firebase/iid/FirebaseInstanceIdTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public void testDeleteInstanceIdTransportError() throws Exception {
220220
} catch (ExecutionException e) {
221221
assertTrue(e.getCause() instanceof FirebaseInstanceIdException);
222222
FirebaseInstanceIdException error = (FirebaseInstanceIdException) e.getCause();
223-
assertEquals(ErrorCode.UNKNOWN, error.getErrorCodeNew());
223+
assertEquals(ErrorCode.UNKNOWN, error.getErrorCode());
224224
assertEquals(
225225
"Unknown error while making a remote service call: transport error",
226226
error.getMessage());
@@ -254,7 +254,7 @@ public void testDeleteInstanceIdInvalidJsonIgnored() throws Exception {
254254
}
255255

256256
private void checkFirebaseInstanceIdException(FirebaseInstanceIdException error, int statusCode) {
257-
assertEquals(ERROR_CODES.get(statusCode), error.getErrorCodeNew());
257+
assertEquals(ERROR_CODES.get(statusCode), error.getErrorCode());
258258
assertEquals(ERROR_MESSAGES.get(statusCode), error.getMessage());
259259
assertTrue(error.getCause() instanceof HttpResponseException);
260260

0 commit comments

Comments
 (0)