Skip to content

Commit 3bb4d1b

Browse files
fix(firebase_remote_config): update exception handling to show actual exception (#9629)
1 parent 2240784 commit 3bb4d1b

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

packages/firebase_remote_config/firebase_remote_config/android/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfig/FirebaseRemoteConfigPlugin.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
1515
import com.google.firebase.remoteconfig.FirebaseRemoteConfigClientException;
1616
import com.google.firebase.remoteconfig.FirebaseRemoteConfigFetchThrottledException;
17+
import com.google.firebase.remoteconfig.FirebaseRemoteConfigServerException;
1718
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;
1819
import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue;
1920
import io.flutter.Log;
@@ -188,6 +189,18 @@ public void onMethodCall(MethodCall call, @NonNull final MethodChannel.Result re
188189
} else if (exception instanceof FirebaseRemoteConfigClientException) {
189190
details.put("code", "internal");
190191
details.put("message", "internal remote config fetch error");
192+
} else if (exception instanceof FirebaseRemoteConfigServerException) {
193+
details.put("code", "remote-config-server-error");
194+
details.put("message", exception.getMessage());
195+
196+
Throwable cause = exception.getCause();
197+
if (cause != null) {
198+
String causeMessage = cause.getMessage();
199+
if (causeMessage != null && causeMessage.contains("Forbidden")) {
200+
// Specific error code for 403 status code to indicate the request was forbidden.
201+
details.put("code", "forbidden");
202+
}
203+
}
191204
} else {
192205
details.put("code", "unknown");
193206
details.put("message", "unknown remote config error");

packages/firebase_remote_config/firebase_remote_config/ios/Classes/FLTFirebaseRemoteConfigUtils.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ + (NSDictionary *)ErrorCodeAndMessageFromNSError:(NSError *)error {
1111
NSMutableDictionary *codeAndMessage = [[NSMutableDictionary alloc] init];
1212
switch (error.code) {
1313
case FIRRemoteConfigErrorInternalError:
14-
[codeAndMessage setValue:@"internal" forKey:@"code"];
15-
[codeAndMessage setValue:error.userInfo[NSLocalizedDescriptionKey] forKey:@"message"];
14+
if ([error.userInfo[NSLocalizedDescriptionKey] containsString:@"403"]) {
15+
// See PR for details: https://github.com/firebase/flutterfire/pull/9629
16+
[codeAndMessage setValue:@"forbidden" forKey:@"code"];
17+
NSString *updateMessage =
18+
[NSString stringWithFormat:@"%@%@", error.userInfo[NSLocalizedDescriptionKey],
19+
@". You may have to enable the Remote Config API on Google "
20+
@"Cloud Platform for your Firebase project."];
21+
[codeAndMessage setValue:updateMessage forKey:@"message"];
22+
} else {
23+
[codeAndMessage setValue:@"internal" forKey:@"code"];
24+
[codeAndMessage setValue:error.userInfo[NSLocalizedDescriptionKey] forKey:@"message"];
25+
}
1626
break;
1727
case FIRRemoteConfigErrorThrottled:
1828
[codeAndMessage setValue:@"throttled" forKey:@"code"];

packages/firebase_remote_config/firebase_remote_config/lib/src/firebase_remote_config.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class FirebaseRemoteConfig extends FirebasePluginPlatform with ChangeNotifier {
8383
/// Performs a fetch and activate operation, as a convenience.
8484
///
8585
/// Returns [bool] in the same way that is done for [activate].
86+
/// A [FirebaseException] maybe thrown with the following error code:
87+
/// - **forbidden**:
88+
/// - Thrown if the Google Cloud Platform Firebase Remote Config API is disabled
8689
Future<bool> fetchAndActivate() async {
8790
bool configChanged = await _delegate.fetchAndActivate();
8891
notifyListeners();

packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/platform_interface/platform_interface_firebase_remote_config.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ abstract class FirebaseRemoteConfigPlatform extends PlatformInterface {
122122
/// Performs a fetch and activate operation, as a convenience.
123123
///
124124
/// Returns [bool] in the same way that is done for [activate].
125+
/// A [FirebaseException] maybe thrown with the following error code:
126+
/// - **forbidden**:
127+
/// - Thrown if the Google Cloud Platform Firebase Remote Config API is disabled
125128
Future<bool> fetchAndActivate() {
126129
throw UnimplementedError('fetchAndActivate() is not implemented');
127130
}

0 commit comments

Comments
 (0)