react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

firebase.config().fetch() returns error "Error: fetch() operation cannot be completed successfully."

Open neerajamnair opened this issue 8 years ago • 28 comments

Issue

Followed the below example using Remote Config. But I am getting error.

if (__DEV__) {
  firebase.config().enableDeveloperMode();
}

// Set default values
firebase.config().setDefaults({
  hasExperimentalFeature: false,
});

firebase.config().fetch()
  .then(() => {
    return firebase.config().activateFetched();
  })
  .then((activated) => {
    if (!activated) console.log('Fetched data not activated');
    return firebase.config().getValue('hasExperimentalFeature');
  })
  .then((snapshot) => {
    const hasExperimentalFeature = snapshot.val();

    if(hasExperimentalFeature) {
      // call some function
    }

    // continue booting app
  })
  .catch(console.error);

It returns an error : Error: fetch() operation cannot be completed successfully

screen shot 2018-08-07 at 3 25 50 pm

Environment

  1. Application Target Platform: Android
  2. Development Operating System: MacOS High Sierra
  3. Build Tools: Xcode buildToolsVersion = "27.0.3" minSdkVersion = 16 compileSdkVersion = 27 targetSdkVersion = 27 supportLibVersion = "27.1.0"
  4. React Native version: 0.56.0
  5. React Native Firebase Version: [email protected]
  6. Firebase Module: Remote Config
  7. Are you using typescript? no

neerajamnair avatar Aug 07 '18 10:08 neerajamnair

Hello - the remote config SDKs throw back errors which are less than helpful at times. If you can, open up Android Studio and run your app in it's debug mode, and place a debug marker on this line.

Or, check the logcat output, the internal SDK may log out something which will help.

Ehesp avatar Aug 07 '18 11:08 Ehesp

I have the same problem. How can we find a solution?

burakduganci avatar Aug 16 '18 13:08 burakduganci

@burakduganci please see my above comment.

Ehesp avatar Aug 17 '18 08:08 Ehesp

I have some problem that the config.fetch promise give me no response, and it is fixed when I upgrade simulator to API 28.

ChiAnTai avatar Aug 27 '18 08:08 ChiAnTai

Please respond with some debugging information and we'll reopen. Thanks.

Ehesp avatar Aug 28 '18 06:08 Ehesp

@Ehesp I removed it since API 28 is too new, but I believe the error should be "Google Play services out of date. Requires 12451000 but found 12221470".(from my Google search record)

ChiAnTai avatar Aug 28 '18 08:08 ChiAnTai

@ChiAnTai I am experiencing this issue on iOS too. Is that a 'Google Play Services' issue too?

jankrah12 avatar Nov 30 '18 16:11 jankrah12

facing the same issue. Any solution?

rohit75 avatar Mar 29 '19 08:03 rohit75

Any solution yet?

dembeEdward avatar Jun 07 '19 13:06 dembeEdward

@dembeEdward this is a closed issue with no debugging information, if you're having issues please open a new issue and follow the template so we know all the versions and steps to reproduce. Also, highly recommend you try to reproduce it either from react-native-firebase-starter or https://github.com/mikehardy/rnfbdemo so you make sure it is not something wrong in your project

mikehardy avatar Jun 07 '19 18:06 mikehardy

My solution was to put the fetch function inside a Promise. Ex:

try {
  return new Promise(
    (resolve) => {
      resolve(
      firebase.config()
      fetch()
        .then(() => {
          return firebase.config().activateFetched();
        })
        .then((activated) => {
          if (!activated) console.log('Fetched data not activated');
          return firebase.config().getValue('hasExperimentalFeature');
        })
        .then((snapshot) => {
          const hasExperimentalFeature = snapshot.val();

          if (hasExperimentalFeature) {
            // call some function
          }

          // continue booting app
        })
        .catch(console.error)
    )
  );
} catch (err) {
  console.warn(err)
}

jezreel8858 avatar Jul 01 '19 18:07 jezreel8858

I am facing the same issue, but adding in a promise did not work @jezreel8858 =/

Does anyone have a solution for this?

OtacilioN avatar Jul 23 '19 17:07 OtacilioN

I followed what @Ehesp said (https://github.com/invertase/react-native-firebase/issues/1376#issuecomment-411031765) and got expired error in Android Studio like this.

E/FirebaseRemoteConfig: Fetch failed! Server responded with an error.
    com.google.android.gms.internal.firebase_remote_config.zze: 400 Bad Request
    {
      "code": 400,
      "errors": [
        {
          "domain": "global",
          "message": "API key expired. Please renew the API key.",
          "reason": "badRequest"
        }
      ],
      "message": "API key expired. Please renew the API key.",
      "status": "INVALID_ARGUMENT"
    }

That might be one of the reasons of this issue.

manakuro avatar Oct 07 '19 03:10 manakuro

This is also failing intermittently for our team, which means that some features are unavailable to our users - Is this related to firebase or something to do with this library?

radiodario avatar Dec 13 '19 12:12 radiodario

Are you able to fetch logcat when it happens? Likely something there indicating the reason. If I recall correctly the throttling on remote config happens much faster than I would have though, maybe that's the underlying cause, as a guess

mikehardy avatar Dec 13 '19 16:12 mikehardy

Hey guys ! In my case, I had the same error message and logcat didn't show anything until i made it talk :p Go to ReactNativeFirebaseConfigModule.java, find the fetch method and do the following:

public void fetch(double expirationDurationSeconds, Promise promise) {
    module.fetch((long) expirationDurationSeconds).addOnCompleteListener(task -> {
      if (task.isSuccessful()) {
        promise.resolve(resultWithConstants(task.getResult()));
      } else {
        // add this line
        Log.e("Tag", "ErrorMessage", task.getException());
        rejectPromiseWithConfigException(promise, task.getException());
      }
    });
  }

You'll now see the right error message. In my case, it was an authentication error (unauthorized).

Alaa-Ben avatar Dec 16 '19 15:12 Alaa-Ben

I patched RNFirebaseRemoteConfig.java to see what the underlying message was. One of the errors I'm getting is "The client had an error while calling the backend". The only other instances of this error were:

  • https://github.com/firebase/firebase-android-sdk/issues/1111
  • https://github.com/firebase/firebase-android-sdk/issues/1515
  • https://stackoverflow.com/questions/60595972/firebaseremoteconfigclientexception-on-production-android

Though could not find anything conclusive, they state that either there was an error with Network, or SSL Handshake.

Here is my patch btw:

--- a/node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/config/RNFirebaseRemoteConfig.java
+++ b/node_modules/react-native-firebase/android/src/main/java/io/invertase/firebase/config/RNFirebaseRemoteConfig.java
@@ -154,9 +154,14 @@ class RNFirebaseRemoteConfig extends ReactContextBaseJavaModule {
                 task.getException()
               );
             } else {
+              Exception exception = task.getException();
+              String message = "";
+              if (exception != null) {
+                message = exception.getMessage();
+              }
               promise.reject(
                 "config/failure",
-                "fetch() operation cannot be completed successfully.",
+                "fetch() operation cannot be completed successfully." + message,
                 task.getException()
               );
             }

azizhk avatar Jun 11 '20 17:06 azizhk

Hi everyone. @azizhk thanks for the patching snippet to unhide the underlying problems behind the fetch() call failure. Should a new issue be created as a followup to enhance the transparency on these cases? Or are we deeming this as a non-issue?

gvitelli avatar Jun 15 '20 17:06 gvitelli

If this one is closed then perhaps - also please :pray: check the upstream android / ios SDK release notes as one of them (I forget which sorry) had a mention of something that seemed like it was in the area

mikehardy avatar Jun 15 '20 17:06 mikehardy

I'm having this happening in production Android Apps, I'm logging the nativeErrorMessage prop of the error in crashlytics and I'm seeing 2 different messages:

  • "The client had an error while calling the backend!"
  • "Failed to get Firebase Instance ID token for fetch."

According to this comment, a full stack trace is needed to correctly identify the issue for the first error, any suggestions on how could I log that without patching the native package?

Also suggestions for debugging the second error would be greatly appreciated 🙏

Paduado avatar Jul 01 '20 23:07 Paduado