How to handle an invalid login to replicator?

Hi

I have an app where the user can register and login. If they have done that then we use their credentials to start the replicator (to get the user specific documents via their channel).

But if the user has either entered a wrong password - or changed it via a browser interface to the same system - then how do I catch this error in the replicator?

I have this code just before I start the replicator:

replListener = this.replicator.AddChangeListener((sender, args) =>
{
   var s = args.Status;
   Logger.Debug($"{replType} Replicator: {s.Progress.Completed}/{s.Progress.Total}, error {s.Error?.Message ?? "<none>"}, activity = {s.Activity}");
});

When providing a wrong login then I get (as expected) something like this:

[DbDataStore] Pull Replicator: 0/0, error CouchbaseLiteException (WebSocketDomain / 401): CouchbaseLiteException (WebSocketDomain / 401): (unknown HTTP status).., activity = Busy
[DbDataStore] Pull Replicator: 0/0, error CouchbaseLiteException (WebSocketDomain / 401): CouchbaseLiteException (WebSocketDomain / 401): (unknown HTTP status).., activity = Stopped

I have tried to “get my hands on” this exception? The s.Error property does not provide me with the web socket information (specifically the 401 error code). I have tried to look in the API documentation and search for examples - but haven’t really found anything that I could use… - and I have not been able to set a breakpoint and stop the code in the event handler…

I would appreciate a little insight on this :slight_smile:

I’m on Sync Gateway 2.5.1 and CB Lite 2.5.3 (C#)

Are you asking how to detect that the error (s.error) is an HTTP 401 status? I don’t know .NET, but the error object should have properties that let you find the error type (subclass?) and numeric code…

Well, that was my question, really…

I have not been able to set a breakpoint (well, yes - but it never stops there) so investigating the error object further is kind of difficult… So far I’m investigating the Message property… - but it’s really not ideal.

So I have tried to cast the error over to a CouchbaseWebsocketException and print all the properties. So I don’t directly get a “401”, but I do get:

[DbDataStore] Error - Domain: CouchbaseLite
[DbDataStore] Error - Error: HTTPAuthRequired

So I guess that is the best bet…