Application flow for Realm Sync Error handling


Can someone help me understand how to use SyncManager to detect and handle sync errors in an application.

When in the application lifecycle should the SyncManager error handler be set - before trying to connect to the ROS or after a successful connection ?

What does SyncSession.immediatelyHandleError() do if it gets called ?

What happens if SyncSession.immediatelyHandleError() is not called ?

I guess some kind of logic flow like below would be useful to understand the process for handling the error and automatically recovering.

  • App startup
  • Check if Realm Sync login required
  • Perform Realm remote login - SyncUser.logIn()
  • Set sync manager error hander - SyncManager.shared.errorHandler = {…}
  • Open sync realm - Realm.asyncOpen()

And when a clientResetError is encountered:

  • close any open realms
  • save reference to backup database
  • restart the app - ??

will the app now automatically download a new copy of the database when reconnecting or is there a need to connect in a specific manner after a clientResetError ? For example - using asyncOpen().

And in the case where SyncSession.immediatelyHandleError(clientResetToken) is called how is the app expected to behave after this call ? Should the app immediately call Realm.asyncOpen() and effectively startup from scratch again - i.e. wait for the database to complete the download and then run the logic to add any missing data from the backup database whose reference was saved when the original clientResetError was received?

When using a Cloud ROS instance how can I simulate a client reset to test the application ?