Skip to content

fix(firebase_remote_config): update exception handling to show actual exception #9629

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 11 commits into from
Feb 7, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigClientException;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigFetchThrottledException;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigServerException;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue;
import io.flutter.Log;
Expand Down Expand Up @@ -188,6 +189,18 @@ public void onMethodCall(MethodCall call, @NonNull final MethodChannel.Result re
} else if (exception instanceof FirebaseRemoteConfigClientException) {
details.put("code", "internal");
details.put("message", "internal remote config fetch error");
} else if (exception instanceof FirebaseRemoteConfigServerException) {
details.put("code", "remote-config-server-error");
details.put("message", exception.getMessage());

Throwable cause = exception.getCause();
if (cause != null) {
String causeMessage = cause.getMessage();
if (causeMessage != null && causeMessage.contains("Forbidden")) {
// Specific error code for 403 status code to indicate the request was forbidden.
details.put("code", "forbidden");
}
}
} else {
details.put("code", "unknown");
details.put("message", "unknown remote config error");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@ + (NSDictionary *)ErrorCodeAndMessageFromNSError:(NSError *)error {
NSMutableDictionary *codeAndMessage = [[NSMutableDictionary alloc] init];
switch (error.code) {
case FIRRemoteConfigErrorInternalError:
[codeAndMessage setValue:@"internal" forKey:@"code"];
[codeAndMessage setValue:error.userInfo[NSLocalizedDescriptionKey] forKey:@"message"];
if ([error.userInfo[NSLocalizedDescriptionKey] containsString:@"403"]) {
// See PR for details: https://github.com/firebase/flutterfire/pull/9629
[codeAndMessage setValue:@"forbidden" forKey:@"code"];
NSString *updateMessage =
[NSString stringWithFormat:@"%@%@", error.userInfo[NSLocalizedDescriptionKey],
@". You may have to enable the Remote Config API on Google "
@"Cloud Platform for your Firebase project."];
[codeAndMessage setValue:updateMessage forKey:@"message"];
} else {
[codeAndMessage setValue:@"internal" forKey:@"code"];
[codeAndMessage setValue:error.userInfo[NSLocalizedDescriptionKey] forKey:@"message"];
}
break;
case FIRRemoteConfigErrorThrottled:
[codeAndMessage setValue:@"throttled" forKey:@"code"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class FirebaseRemoteConfig extends FirebasePluginPlatform with ChangeNotifier {
/// Performs a fetch and activate operation, as a convenience.
///
/// Returns [bool] in the same way that is done for [activate].
/// A [FirebaseException] maybe thrown with the following error code:
/// - **forbidden**:
/// - Thrown if the Google Cloud Platform Firebase Remote Config API is disabled
Future<bool> fetchAndActivate() async {
bool configChanged = await _delegate.fetchAndActivate();
notifyListeners();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ abstract class FirebaseRemoteConfigPlatform extends PlatformInterface {
/// Performs a fetch and activate operation, as a convenience.
///
/// Returns [bool] in the same way that is done for [activate].
/// A [FirebaseException] maybe thrown with the following error code:
/// - **forbidden**:
/// - Thrown if the Google Cloud Platform Firebase Remote Config API is disabled
Future<bool> fetchAndActivate() {
throw UnimplementedError('fetchAndActivate() is not implemented');
}
Expand Down