Which error codes coming from the replicator should our code handle?

In our code we want to handle error events from the Sync Gateway by sending a disconnect broadcast. We basically look for any 4xx, 5xx, or 6xx error code here. My question is if the Sync Gateway would ever send an error code in the range of 400-699 during normal operation that we should not disconnect the user for?

    public void changed(com.couchbase.lite.replicator.Replication.ChangeEvent event) {
        ...
        Throwable lastError = event.getError();
            if (lastError instanceof RemoteRequestResponseException) {
                RemoteRequestResponseException exception = (RemoteRequestResponseException) lastError;
                if (exception.getCode() >= 400 &&  exception.getCode() < 700) {
                    mSource.sendDisconnectedBroadcast();
                }
            }
        ...
    }
1 Like

If you’re looking for connection problems, look at the replicator status instead.

  • A one-shot replicator will stop if it has a serious connection problem (after retrying a few times.)
  • A continuous replicator will go to the Offline state, and retry periodically.

Thank you for your Quick reply.
I tried to check the status (== REPLICATION_STOPPED), and it looks like not working as expected. I got this status when a Sync Gateway session expires, but I got it as well earlier without any session expired… so I cannot send a disconnect broadcast based on this status.

Is there any code error between 400 - 699 that we should not catch, otherwise we send the disconnect broadcast (the replicator may be still working and retry the connection, etc so we do not have to intervene)?

Thank you.

I tried to check the status (== REPLICATION_STOPPED), and it looks like not working as expected. I got this status when a Sync Gateway session expires, but I got it as well earlier without any session expired

A one-shot replicator will stop when the replication is done, or if it can’t (re)connect. Session expiry definitely isn’t the only explanation.

I don’t understand what it is you’re trying to do. What do you mean by “send a disconnect broadcast”?