Skip to content

Replace old realtime exceptions with new exceptions #4304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 17, 2022
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
32 changes: 20 additions & 12 deletions firebase-config/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package com.google.firebase.remoteconfig {

public interface ConfigUpdateListener {
method public void onError(@NonNull Exception);
method public void onError(@NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException);
method public void onEvent();
}

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

public class FirebaseRemoteConfig {
method @NonNull public com.google.android.gms.tasks.Task<java.lang.Boolean> activate();
method public com.google.firebase.remoteconfig.ConfigUpdateListenerRegistration addOnConfigUpdateListener(@NonNull com.google.firebase.remoteconfig.ConfigUpdateListener);
method @NonNull public com.google.firebase.remoteconfig.ConfigUpdateListenerRegistration addOnConfigUpdateListener(@NonNull com.google.firebase.remoteconfig.ConfigUpdateListener);
method @NonNull public com.google.android.gms.tasks.Task<com.google.firebase.remoteconfig.FirebaseRemoteConfigInfo> ensureInitialized();
method @NonNull public com.google.android.gms.tasks.Task<java.lang.Void> fetch();
method @NonNull public com.google.android.gms.tasks.Task<java.lang.Void> fetch(long);
Expand Down Expand Up @@ -48,11 +48,25 @@ package com.google.firebase.remoteconfig {
public class FirebaseRemoteConfigClientException extends com.google.firebase.remoteconfig.FirebaseRemoteConfigException {
ctor public FirebaseRemoteConfigClientException(@NonNull String);
ctor public FirebaseRemoteConfigClientException(@NonNull String, @Nullable Throwable);
ctor public FirebaseRemoteConfigClientException(@NonNull String, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
ctor public FirebaseRemoteConfigClientException(@NonNull String, @Nullable Throwable, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
}

public class FirebaseRemoteConfigException extends com.google.firebase.FirebaseException {
ctor public FirebaseRemoteConfigException(@NonNull String);
ctor public FirebaseRemoteConfigException(@NonNull String, @Nullable Throwable);
ctor public FirebaseRemoteConfigException(@NonNull String, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
ctor public FirebaseRemoteConfigException(@NonNull String, @Nullable Throwable, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
method @NonNull public com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code getCode();
}

public enum FirebaseRemoteConfigException.Code {
method public int value();
enum_constant public static final com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code CONFIG_UPDATE_MESSAGE_INVALID;
enum_constant public static final com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code CONFIG_UPDATE_NOT_FETCHED;
enum_constant public static final com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code CONFIG_UPDATE_STREAM_ERROR;
enum_constant public static final com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code CONFIG_UPDATE_UNAVAILABLE;
enum_constant public static final com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code UNKNOWN;
}

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

public class FirebaseRemoteConfigRealtimeUpdateFetchException extends com.google.firebase.remoteconfig.FirebaseRemoteConfigException {
ctor public FirebaseRemoteConfigRealtimeUpdateFetchException(@NonNull String);
ctor public FirebaseRemoteConfigRealtimeUpdateFetchException(@NonNull String, @Nullable Throwable);
}

public class FirebaseRemoteConfigRealtimeUpdateStreamException extends com.google.firebase.remoteconfig.FirebaseRemoteConfigException {
ctor public FirebaseRemoteConfigRealtimeUpdateStreamException(@NonNull String);
ctor public FirebaseRemoteConfigRealtimeUpdateStreamException(@NonNull String, @Nullable Throwable);
}

public class FirebaseRemoteConfigServerException extends com.google.firebase.remoteconfig.FirebaseRemoteConfigException {
ctor public FirebaseRemoteConfigServerException(int, @NonNull String);
ctor public FirebaseRemoteConfigServerException(int, @NonNull String, @Nullable Throwable);
ctor public FirebaseRemoteConfigServerException(@NonNull String, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
ctor public FirebaseRemoteConfigServerException(int, @NonNull String, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
ctor public FirebaseRemoteConfigServerException(@NonNull String, @Nullable Throwable, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
ctor public FirebaseRemoteConfigServerException(int, @NonNull String, @Nullable Throwable, @NonNull com.google.firebase.remoteconfig.FirebaseRemoteConfigException.Code);
method public int getHttpStatusCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ public interface ConfigUpdateListener {
*
* @param error
*/
void onError(@Nonnull Exception error);
void onError(@Nonnull FirebaseRemoteConfigException error);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,21 @@ public FirebaseRemoteConfigClientException(
@NonNull String detailMessage, @Nullable Throwable cause) {
super(detailMessage, cause);
}

/**
* Creates a Firebase Remote Config client exception with the given message and
* FirebaseRemoteConfigException code.
*/
public FirebaseRemoteConfigClientException(@NonNull String detailMessage, @NonNull Code code) {
super(detailMessage, code);
}

/**
* Creates a Firebase Remote Config client exception with the given message, exception cause, and
* FirebaseRemoteConfigException code.
*/
public FirebaseRemoteConfigClientException(
@NonNull String detailMessage, @Nullable Throwable cause, @NonNull Code code) {
super(detailMessage, cause, code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,63 @@

/** Base class for {@link FirebaseRemoteConfig} exceptions. */
public class FirebaseRemoteConfigException extends FirebaseException {
/** Code that specifies the type of exception. */
private final Code code;

/** Creates a Firebase Remote Config exception with the given message. */
public FirebaseRemoteConfigException(@NonNull String detailMessage) {
super(detailMessage);
this.code = Code.UNKNOWN;
}

/** Creates a Firebase Remote Config exception with the given message and cause. */
public FirebaseRemoteConfigException(@NonNull String detailMessage, @Nullable Throwable cause) {
super(detailMessage, cause);
this.code = Code.UNKNOWN;
}

/** Creates a Firebase Remote Config exception with the given message and Code. */
public FirebaseRemoteConfigException(@NonNull String detailMessage, @NonNull Code code) {
super(detailMessage);
this.code = code;
}

/** Creates a Firebase Remote Config exception with the given message, cause, and Code. */
public FirebaseRemoteConfigException(
@NonNull String detailMessage, @Nullable Throwable cause, @NonNull Code code) {
super(detailMessage, cause);
this.code = code;
}

public enum Code {
/** The stream was not able to connect to the backend. */
CONFIG_UPDATE_STREAM_ERROR(0),

/** The stream invalidation message was unparsable. */
CONFIG_UPDATE_MESSAGE_INVALID(1),

/** Unable to fetch the latest config. */
CONFIG_UPDATE_NOT_FETCHED(2),

/** The Realtime service is unavailable. */
CONFIG_UPDATE_UNAVAILABLE(3),

/** Unknown code value. */
UNKNOWN(4);

private final int value;

Code(int value) {
this.value = value;
}

public int value() {
return value;
}
}

@NonNull
public Code getCode() {
return code;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import javax.annotation.Nonnull;

/**
* A Firebase Remote Config internal issue caused by an interaction with the Firebase Remote Config
Expand Down Expand Up @@ -43,6 +44,48 @@ public FirebaseRemoteConfigServerException(
this.httpStatusCode = httpStatusCode;
}

/**
* Creates a Firebase Remote Config server exception with the given message and
* FirebaseRemoteConfigException code.
*/
public FirebaseRemoteConfigServerException(@NonNull String detailMessage, @Nonnull Code code) {
super(detailMessage, code);
this.httpStatusCode = -1;
}

/**
* Creates a Firebase Remote Config server exception with the HTTP status code, given message, and
* FirebaseRemoteConfigException code.
*/
public FirebaseRemoteConfigServerException(
int httpStatusCode, @NonNull String detailMessage, @Nonnull Code code) {
super(detailMessage, code);
this.httpStatusCode = httpStatusCode;
}

/**
* Creates a Firebase Remote Config server exception with the given message, exception cause, and
* FirebaseRemoteConfigException code.
*/
public FirebaseRemoteConfigServerException(
@NonNull String detailMessage, @Nullable Throwable cause, @NonNull Code code) {
super(detailMessage, cause, code);
this.httpStatusCode = -1;
}

/**
* Creates a Firebase Remote Config server exception with the HTTP status code, given message,
* exception cause, and FirebaseRemoteConfigException code.
*/
public FirebaseRemoteConfigServerException(
int httpStatusCode,
@NonNull String detailMessage,
@Nullable Throwable cause,
@NonNull Code code) {
super(detailMessage, cause, code);
this.httpStatusCode = httpStatusCode;
}

/** Gets the HTTP status code of the failed Firebase Remote Config server operation. */
public int getHttpStatusCode() {
return httpStatusCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.Tasks;
import com.google.firebase.remoteconfig.ConfigUpdateListener;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigClientException;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigException;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigRealtimeUpdateFetchException;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigRealtimeUpdateStreamException;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigServerException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -102,8 +102,10 @@ public void listenForNotifications() {
inputStream.close();
} catch (IOException ex) {
propagateErrors(
new FirebaseRemoteConfigRealtimeUpdateFetchException(
"Error handling stream messages while fetching.", ex.getCause()));
new FirebaseRemoteConfigClientException(
"Unable to parse config update message.",
ex.getCause(),
FirebaseRemoteConfigException.Code.CONFIG_UPDATE_MESSAGE_INVALID));
} finally {
httpURLConnection.disconnect();
}
Expand Down Expand Up @@ -144,7 +146,9 @@ private void handleNotifications(InputStream inputStream) throws IOException {
if (jsonObject.has(REALTIME_DISABLED_KEY)
&& jsonObject.getBoolean(REALTIME_DISABLED_KEY)) {
retryCallback.onError(
new FirebaseRemoteConfigRealtimeUpdateStreamException("Realtime is disabled."));
new FirebaseRemoteConfigServerException(
"The server is temporarily unavailable. Try again in a few minutes.",
FirebaseRemoteConfigException.Code.CONFIG_UPDATE_UNAVAILABLE));
break;
}
if (jsonObject.has(TEMPLATE_VERSION_KEY)) {
Expand All @@ -170,7 +174,9 @@ private void handleNotifications(InputStream inputStream) throws IOException {
private void autoFetch(int remainingAttempts, long targetVersion) {
if (remainingAttempts == 0) {
propagateErrors(
new FirebaseRemoteConfigRealtimeUpdateFetchException("Unable to fetch latest version."));
new FirebaseRemoteConfigServerException(
"Unable to fetch the latest version of the template.",
FirebaseRemoteConfigException.Code.CONFIG_UPDATE_NOT_FETCHED));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.firebase.installations.FirebaseInstallationsApi;
import com.google.firebase.remoteconfig.ConfigUpdateListener;
import com.google.firebase.remoteconfig.ConfigUpdateListenerRegistration;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigException;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -159,6 +160,6 @@ public static class EmptyConfigUpdateListener implements ConfigUpdateListener {
public void onEvent() {}

@Override
public void onError(@NonNull Exception error) {}
public void onError(@NonNull FirebaseRemoteConfigException error) {}
}
}
Loading