Merge pull request #1295 from invertase/fix-1288
[config][android] Handle remote config error
This commit is contained in:
commit
ce513f20e9
|
@ -16,6 +16,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
|||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.google.firebase.FirebaseApp;
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfigFetchThrottledException;
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue;
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;
|
||||
|
||||
|
@ -119,9 +120,13 @@ class RNFirebaseRemoteConfig extends ReactContextBaseJavaModule {
|
|||
@Override
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
if (task.isSuccessful()) {
|
||||
promise.resolve("remoteConfigFetchStatusSuccess");
|
||||
promise.resolve(null);
|
||||
} else {
|
||||
promise.reject("config/failure", task.getException().getMessage(), task.getException());
|
||||
if (task.getException() instanceof FirebaseRemoteConfigFetchThrottledException) {
|
||||
promise.reject("config/throttled", "fetch() operation cannot be completed successfully, due to throttling.", task.getException());
|
||||
} else {
|
||||
promise.reject("config/failure", "fetch() operation cannot be completed successfully.", task.getException());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -154,7 +159,6 @@ class RNFirebaseRemoteConfig extends ReactContextBaseJavaModule {
|
|||
map.putNull(NUMBER_VALUE);
|
||||
}
|
||||
|
||||
// TODO check with ios
|
||||
switch (value.getSource()) {
|
||||
case FirebaseRemoteConfig.VALUE_SOURCE_DEFAULT:
|
||||
map.putString(SOURCE, "default");
|
||||
|
|
|
@ -19,6 +19,16 @@ NSString *convertFIRRemoteConfigFetchStatusToNSString(FIRRemoteConfigFetchStatus
|
|||
}
|
||||
}
|
||||
|
||||
NSString *convertFIRRemoteConfigFetchStatusToNSStringDescription(FIRRemoteConfigFetchStatus value) {
|
||||
switch (value) {
|
||||
case FIRRemoteConfigFetchStatusThrottled:
|
||||
return @"fetch() operation cannot be completed successfully, due to throttling.";
|
||||
case FIRRemoteConfigFetchStatusNoFetchYet:
|
||||
default:
|
||||
return @"fetch() operation cannot be completed successfully.";
|
||||
}
|
||||
}
|
||||
|
||||
NSString *convertFIRRemoteConfigSourceToNSString(FIRRemoteConfigSource value) {
|
||||
switch (value) {
|
||||
case FIRRemoteConfigSourceDefault:
|
||||
|
@ -49,9 +59,9 @@ RCT_EXPORT_METHOD(fetch:
|
|||
(RCTPromiseRejectBlock) reject) {
|
||||
[[FIRRemoteConfig remoteConfig] fetchWithCompletionHandler:^(FIRRemoteConfigFetchStatus status, NSError *__nullable error) {
|
||||
if (error) {
|
||||
reject(convertFIRRemoteConfigFetchStatusToNSString(status), error.localizedDescription, error);
|
||||
reject(convertFIRRemoteConfigFetchStatusToNSString(status), convertFIRRemoteConfigFetchStatusToNSStringDescription(status), error);
|
||||
} else {
|
||||
resolve(convertFIRRemoteConfigFetchStatusToNSString(status));
|
||||
resolve(nil);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
@ -63,9 +73,9 @@ RCT_EXPORT_METHOD(fetchWithExpirationDuration:
|
|||
rejecter:(RCTPromiseRejectBlock)reject) {
|
||||
[[FIRRemoteConfig remoteConfig] fetchWithExpirationDuration:expirationDuration.doubleValue completionHandler:^(FIRRemoteConfigFetchStatus status, NSError *__nullable error) {
|
||||
if (error) {
|
||||
reject(convertFIRRemoteConfigFetchStatusToNSString(status), error.localizedDescription, error);
|
||||
reject(convertFIRRemoteConfigFetchStatusToNSString(status), convertFIRRemoteConfigFetchStatusToNSStringDescription(status), error);
|
||||
} else {
|
||||
resolve(convertFIRRemoteConfigFetchStatusToNSString(status));
|
||||
resolve(nil);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue