Realm.Sync.ChangeEvent Handler ClientReset

ros
platform
cloud

#1

How do you handle a ClientReset error in a Realm.Sync.ChangeEvent handler?

We are investigating using Realm for a product and have written a number of handlers to inspect state changes in the backend. Our goal is to use Realm as an interface to our backend functionality. We are currently using Realm Cloud.

We have been recently getting a number of 209 errors that disconnect us from observing state changes. Reading the documentation it tells us to perform a ClientReset to connect back with the correct state but these examples all focus on capturing the event from the error object in the SyncConfiguration. Since we are using Realm.Sync.addListener we don’t have a SyncConfiguration object.

How do we go about preforming a ClientSync from a handler or reconnecting after a 209 error from a handler?
(ERROR=“209”)

const credentials = RealmPackage.Sync.Credentials.usernamePassword(
        config.realm.username,
        config.realm.password,
        false
    );

    RealmPackage.Sync.setLogLevel("info");

    adminUser = await RealmPackage.Sync.User.login(
        `https://${config.realm.host}`,
        credentials
    );
    console.log("logged In");

    const realmConfig : Realm.Sync.RealmListenerConfiguration = {
        serverUrl : `realms://${config.realm.host}`,
        adminUser,
        filterRegex : '^/([^/]+)/test-location-2$'
    }

    await RealmPackage.Sync.addListener(realmConfig, 'change', handleChange);
    console.log("addListener called");