1

I'm trying to catch a case when the app creating a document, but at that moment the connection was lost. So I expect to OnFailureListener or OnCanceledListener get called, but no one callback called at all in this case. How can I catch errors while creating a document while .add() or .set()? Thanks.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Konstantin Konopko
  • 5,229
  • 4
  • 36
  • 62
  • It does not trigger anything if the network is lost. it just writes those changes to the local cache once the network is active its write those changes to the firestore. – Arpan Sarkar Nov 18 '21 at 12:06

1 Answers1

1

As already @ArpanSarkar mentioned in his comment, neither the OnFailureListener nor the OnCanceledListener gets triggered when there is a loss of network connectivity (there is no network connection on the user device). So the Firestore SDK doesn't throw an Exception when there is no internet connection. And it makes sense since Firestore is designed to work offline. Behind the scenes, Firestore SDK tries to reconnect until the devices regain connectivity. That being said, please note that all the writes that are made while offline, are added to a queue, and once the device regains internet connectivity everything will be synced with the Firebase servers.

On the other hand, an Exception will be thrown, only when the data has been committed (or rejected) on the Firebase server, for example, due to improper security rules.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193