Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Google Firestore .set() doesn't calling failure listener when connection lost

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.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading