I tried to check the LastError property of the Replication Pull and Status, all I got is
LastError = null, Status = Idle.
But when I check the Sync Gateway log, I can clearly see the session is expired:
015-11-09T11:23:50.401+09:00 HTTP: #430: --> 401 Login required (0.4 ms)
I think something else may be going on here. If you got that response it will show up as a LastError of Unauthorized. Can you clear the sync gateway log and restart the program to make sure that you aren’t viewing a log from a previous entry?
Sorry, my mistake, the log I wrote is coming from the replication Push session expired.
But I notice that seem like even the replication Push session expired, the LastError property will be null until someone do modification on database, triggering Pull and set the LastError property to Unauthorized…?
There is no separate mechanism to inform you of an expiring session. What you said is correct. You will not know about an expiration until you try to use a replication and get an unauthorized response. The LastError property means the error that happened during the last attempt to synchronize data.
Just curious, how does the replication Pull knows there are changes on database even the session expired?
There are separate access/notification to check if there is changes on database which doesn’t require authentication/session?
The puller gets this information by basically asking the remote database. There are quite a number of requests and responses involved in a replication, but there is an overview diagram you can look at to try to understand it better.
Mind if I ask you one more question?
When session expired, replication Push LastError returns HttpReponseException, StatusCode = Unauthorized, which is perfect and fine for me.
But replication Pull LastError returns CouchbaseLiteException as follows:
base = "Couchbase.Lite.CouchbaseLiteException: Change tracker got error with status code: Unauthorized"
CBLStatus = “Status: Reserved”
How can I get the real Unauthorized Status Code from exception to determine if is unauthorized?