0
votes

I see a lot of network troubles now. In the JavaScript console I see this message:

@firebase/firestore: Firestore (7.14.2): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds. This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

Can I catch this somehow and show it to the user?


EDIT: A clarification. This message is not a problem when the web browser is offline. In that case everything work as I expect it to. I have this in my code:

await firebase.firestore().enablePersistence({ synchronizeTabs: true })

However when navigator.onLine === true but Firestore can't be reach I first see the console message above. After that I get an error that I catch:

Uncaught (in promise) FirebaseError: Failed to get document because the client is offline.

This message is wrong. The browser is not offline. It is Firebase that is "offline" (from the browswer's point of view).

I can surely decode that message and give the user correct information, but I would rather have an official way to handle this.

1

1 Answers

1
votes

That's not an error, that's a notice. It can't be caught. It's telling you that the Firestore SDK is finding it difficult to reach the Firestore service and will only use cache until that resolves. Being offline isn't an error condition, as the Firestore SDK was built to be used offline temporarily as a normal case.

You might want to read more about how the Firestore cache works.