Skip to content

Commit bb55c49

Browse files
authored
Merge e2894dc into 290a487
2 parents 290a487 + e2894dc commit bb55c49

11 files changed

+206
-119
lines changed

firebase-config/api.txt

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
package com.google.firebase.remoteconfig {
33

44
public interface ConfigUpdateListener {
5-
method public void onError(@NonNull Exception);
5+
method public void onError(@NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException);
66
method public void onEvent();
77
}
88

@@ -12,7 +12,7 @@ package com.google.firebase.remoteconfig {
1212

1313
public class FirebaseRemoteConfig {
1414
method @NonNull public com.google.android.gms.tasks.Task<java.lang.Boolean> activate();
15-
method public com.google.firebase.remoteconfig.ConfigUpdateListenerRegistration addOnConfigUpdateListener(@NonNull com.google.firebase.remoteconfig.ConfigUpdateListener);
15+
method @NonNull public com.google.firebase.remoteconfig.ConfigUpdateListenerRegistration addOnConfigUpdateListener(@NonNull com.google.firebase.remoteconfig.ConfigUpdateListener);
1616
method @NonNull public com.google.android.gms.tasks.Task<com.google.firebase.remoteconfig.FirebaseRemoteConfigInfo> ensureInitialized();
1717
method @NonNull public com.google.android.gms.tasks.Task<java.lang.Void> fetch();
1818
method @NonNull public com.google.android.gms.tasks.Task<java.lang.Void> fetch(long);
@@ -48,11 +48,25 @@ package com.google.firebase.remoteconfig {
4848
public class FirebaseRemoteConfigClientException extends com.google.firebase.remoteconfig.FirebaseRemoteConfigException {
4949
ctor public FirebaseRemoteConfigClientException(@NonNull String);
5050
ctor public FirebaseRemoteConfigClientException(@NonNull String, @Nullable Throwable);
51+
ctor public FirebaseRemoteConfigClientException(@NonNull String, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
52+
ctor public FirebaseRemoteConfigClientException(@NonNull String, @Nullable Throwable, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
5153
}
5254

5355
public class FirebaseRemoteConfigException extends com.google.firebase.FirebaseException {
5456
ctor public FirebaseRemoteConfigException(@NonNull String);
5557
ctor public FirebaseRemoteConfigException(@NonNull String, @Nullable Throwable);
58+
ctor public FirebaseRemoteConfigException(@NonNull String, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
59+
ctor public FirebaseRemoteConfigException(@NonNull String, @Nullable Throwable, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
60+
method @NonNull public com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code getCode();
61+
}
62+
63+
public enum FirebaseRemoteConfigException.Code {
64+
method public int value();
65+
enum_constant public static final com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code CONFIG_UPDATE_MESSAGE_INVALID;
66+
enum_constant public static final com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code CONFIG_UPDATE_NOT_FETCHED;
67+
enum_constant public static final com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code CONFIG_UPDATE_STREAM_ERROR;
68+
enum_constant public static final com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code CONFIG_UPDATE_UNAVAILABLE;
69+
enum_constant public static final com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code UNKNOWN;
5670
}
5771

5872
public class FirebaseRemoteConfigFetchThrottledException extends com.google.firebase.remoteconfig.FirebaseRemoteConfigException {
@@ -66,19 +80,13 @@ package com.google.firebase.remoteconfig {
6680
method public int getLastFetchStatus();
6781
}
6882

69-
public class FirebaseRemoteConfigRealtimeUpdateFetchException extends com.google.firebase.remoteconfig.FirebaseRemoteConfigException {
70-
ctor public FirebaseRemoteConfigRealtimeUpdateFetchException(@NonNull String);
71-
ctor public FirebaseRemoteConfigRealtimeUpdateFetchException(@NonNull String, @Nullable Throwable);
72-
}
73-
74-
public class FirebaseRemoteConfigRealtimeUpdateStreamException extends com.google.firebase.remoteconfig.FirebaseRemoteConfigException {
75-
ctor public FirebaseRemoteConfigRealtimeUpdateStreamException(@NonNull String);
76-
ctor public FirebaseRemoteConfigRealtimeUpdateStreamException(@NonNull String, @Nullable Throwable);
77-
}
78-
7983
public class FirebaseRemoteConfigServerException extends com.google.firebase.remoteconfig.FirebaseRemoteConfigException {
8084
ctor public FirebaseRemoteConfigServerException(int, @NonNull String);
8185
ctor public FirebaseRemoteConfigServerException(int, @NonNull String, @Nullable Throwable);
86+
ctor public FirebaseRemoteConfigServerException(@NonNull String, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
87+
ctor public FirebaseRemoteConfigServerException(int, @NonNull String, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
88+
ctor public FirebaseRemoteConfigServerException(@NonNull String, @Nullable Throwable, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
89+
ctor public FirebaseRemoteConfigServerException(int, @NonNull String, @Nullable Throwable, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
8290
method public int getHttpStatusCode();
8391
}
8492

firebase-config/src/main/java/com/google/firebase/remoteconfig/ConfigUpdateListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ public interface ConfigUpdateListener {
3333
*
3434
* @param error
3535
*/
36-
void onError(@Nonnull Exception error);
36+
void onError(@Nonnull FirebaseRemoteConfigException error);
3737
}

firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientException.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,21 @@ public FirebaseRemoteConfigClientException(
3434
@NonNull String detailMessage, @Nullable Throwable cause) {
3535
super(detailMessage, cause);
3636
}
37+
38+
/**
39+
* Creates a Firebase Remote Config client exception with the given message and
40+
* FirebaseRemoteConfigException code.
41+
*/
42+
public FirebaseRemoteConfigClientException(@NonNull String detailMessage, @NonNull Code code) {
43+
super(detailMessage, code);
44+
}
45+
46+
/**
47+
* Creates a Firebase Remote Config client exception with the given message, exception cause, and
48+
* FirebaseRemoteConfigException code.
49+
*/
50+
public FirebaseRemoteConfigClientException(
51+
@NonNull String detailMessage, @Nullable Throwable cause, @NonNull Code code) {
52+
super(detailMessage, cause, code);
53+
}
3754
}

firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigException.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,63 @@
2020

2121
/** Base class for {@link FirebaseRemoteConfig} exceptions. */
2222
public class FirebaseRemoteConfigException extends FirebaseException {
23+
/** Code that specifies the type of exception. */
24+
private final Code code;
25+
2326
/** Creates a Firebase Remote Config exception with the given message. */
2427
public FirebaseRemoteConfigException(@NonNull String detailMessage) {
2528
super(detailMessage);
29+
this.code = Code.UNKNOWN;
2630
}
2731

2832
/** Creates a Firebase Remote Config exception with the given message and cause. */
2933
public FirebaseRemoteConfigException(@NonNull String detailMessage, @Nullable Throwable cause) {
3034
super(detailMessage, cause);
35+
this.code = Code.UNKNOWN;
36+
}
37+
38+
/** Creates a Firebase Remote Config exception with the given message and Code. */
39+
public FirebaseRemoteConfigException(@NonNull String detailMessage, @NonNull Code code) {
40+
super(detailMessage);
41+
this.code = code;
42+
}
43+
44+
/** Creates a Firebase Remote Config exception with the given message, cause, and Code. */
45+
public FirebaseRemoteConfigException(
46+
@NonNull String detailMessage, @Nullable Throwable cause, @NonNull Code code) {
47+
super(detailMessage, cause);
48+
this.code = code;
49+
}
50+
51+
public enum Code {
52+
/** The stream was not able to connect to the backend. */
53+
CONFIG_UPDATE_STREAM_ERROR(0),
54+
55+
/** The stream invalidation message was unparsable. */
56+
CONFIG_UPDATE_MESSAGE_INVALID(1),
57+
58+
/** Unable to fetch the latest config. */
59+
CONFIG_UPDATE_NOT_FETCHED(2),
60+
61+
/** The Realtime service is unavailable. */
62+
CONFIG_UPDATE_UNAVAILABLE(3),
63+
64+
/** Unknown code value. */
65+
UNKNOWN(4);
66+
67+
private final int value;
68+
69+
Code(int value) {
70+
this.value = value;
71+
}
72+
73+
public int value() {
74+
return value;
75+
}
76+
}
77+
78+
@NonNull
79+
public Code getCode() {
80+
return code;
3181
}
3282
}

firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigRealtimeUpdateFetchException.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigRealtimeUpdateStreamException.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

firebase-config/src/main/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigServerException.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import androidx.annotation.NonNull;
1818
import androidx.annotation.Nullable;
19+
import javax.annotation.Nonnull;
1920

2021
/**
2122
* A Firebase Remote Config internal issue caused by an interaction with the Firebase Remote Config
@@ -43,6 +44,48 @@ public FirebaseRemoteConfigServerException(
4344
this.httpStatusCode = httpStatusCode;
4445
}
4546

47+
/**
48+
* Creates a Firebase Remote Config server exception with the given message and
49+
* FirebaseRemoteConfigException code.
50+
*/
51+
public FirebaseRemoteConfigServerException(@NonNull String detailMessage, @Nonnull Code code) {
52+
super(detailMessage, code);
53+
this.httpStatusCode = -1;
54+
}
55+
56+
/**
57+
* Creates a Firebase Remote Config server exception with the HTTP status code, given message, and
58+
* FirebaseRemoteConfigException code.
59+
*/
60+
public FirebaseRemoteConfigServerException(
61+
int httpStatusCode, @NonNull String detailMessage, @Nonnull Code code) {
62+
super(detailMessage, code);
63+
this.httpStatusCode = httpStatusCode;
64+
}
65+
66+
/**
67+
* Creates a Firebase Remote Config server exception with the given message, exception cause, and
68+
* FirebaseRemoteConfigException code.
69+
*/
70+
public FirebaseRemoteConfigServerException(
71+
@NonNull String detailMessage, @Nullable Throwable cause, @NonNull Code code) {
72+
super(detailMessage, cause, code);
73+
this.httpStatusCode = -1;
74+
}
75+
76+
/**
77+
* Creates a Firebase Remote Config server exception with the HTTP status code, given message,
78+
* exception cause, and FirebaseRemoteConfigException code.
79+
*/
80+
public FirebaseRemoteConfigServerException(
81+
int httpStatusCode,
82+
@NonNull String detailMessage,
83+
@Nullable Throwable cause,
84+
@NonNull Code code) {
85+
super(detailMessage, cause, code);
86+
this.httpStatusCode = httpStatusCode;
87+
}
88+
4689
/** Gets the HTTP status code of the failed Firebase Remote Config server operation. */
4790
public int getHttpStatusCode() {
4891
return httpStatusCode;

firebase-config/src/main/java/com/google/firebase/remoteconfig/internal/ConfigAutoFetch.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
import com.google.android.gms.tasks.Task;
2323
import com.google.android.gms.tasks.Tasks;
2424
import com.google.firebase.remoteconfig.ConfigUpdateListener;
25+
import com.google.firebase.remoteconfig.FirebaseRemoteConfigClientException;
2526
import com.google.firebase.remoteconfig.FirebaseRemoteConfigException;
26-
import com.google.firebase.remoteconfig.FirebaseRemoteConfigRealtimeUpdateFetchException;
27-
import com.google.firebase.remoteconfig.FirebaseRemoteConfigRealtimeUpdateStreamException;
27+
import com.google.firebase.remoteconfig.FirebaseRemoteConfigServerException;
2828
import java.io.BufferedReader;
2929
import java.io.IOException;
3030
import java.io.InputStream;
@@ -102,8 +102,10 @@ public void listenForNotifications() {
102102
inputStream.close();
103103
} catch (IOException ex) {
104104
propagateErrors(
105-
new FirebaseRemoteConfigRealtimeUpdateFetchException(
106-
"Error handling stream messages while fetching.", ex.getCause()));
105+
new FirebaseRemoteConfigClientException(
106+
"Unable to parse config update message.",
107+
ex.getCause(),
108+
FirebaseRemoteConfigException.Code.CONFIG_UPDATE_MESSAGE_INVALID));
107109
} finally {
108110
httpURLConnection.disconnect();
109111
}
@@ -144,7 +146,9 @@ private void handleNotifications(InputStream inputStream) throws IOException {
144146
if (jsonObject.has(REALTIME_DISABLED_KEY)
145147
&& jsonObject.getBoolean(REALTIME_DISABLED_KEY)) {
146148
retryCallback.onError(
147-
new FirebaseRemoteConfigRealtimeUpdateStreamException("Realtime is disabled."));
149+
new FirebaseRemoteConfigServerException(
150+
"The server is temporarily unavailable. Try again in a few minutes.",
151+
FirebaseRemoteConfigException.Code.CONFIG_UPDATE_UNAVAILABLE));
148152
break;
149153
}
150154
if (jsonObject.has(TEMPLATE_VERSION_KEY)) {
@@ -170,7 +174,9 @@ private void handleNotifications(InputStream inputStream) throws IOException {
170174
private void autoFetch(int remainingAttempts, long targetVersion) {
171175
if (remainingAttempts == 0) {
172176
propagateErrors(
173-
new FirebaseRemoteConfigRealtimeUpdateFetchException("Unable to fetch latest version."));
177+
new FirebaseRemoteConfigServerException(
178+
"Unable to fetch the latest version of the template.",
179+
FirebaseRemoteConfigException.Code.CONFIG_UPDATE_NOT_FETCHED));
174180
return;
175181
}
176182

firebase-config/src/main/java/com/google/firebase/remoteconfig/internal/ConfigRealtimeHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.firebase.installations.FirebaseInstallationsApi;
2222
import com.google.firebase.remoteconfig.ConfigUpdateListener;
2323
import com.google.firebase.remoteconfig.ConfigUpdateListenerRegistration;
24+
import com.google.firebase.remoteconfig.FirebaseRemoteConfigException;
2425
import java.util.LinkedHashSet;
2526
import java.util.Set;
2627
import java.util.concurrent.ExecutorService;
@@ -159,6 +160,6 @@ public static class EmptyConfigUpdateListener implements ConfigUpdateListener {
159160
public void onEvent() {}
160161

161162
@Override
162-
public void onError(@NonNull Exception error) {}
163+
public void onError(@NonNull FirebaseRemoteConfigException error) {}
163164
}
164165
}

0 commit comments

Comments
 (0)