Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle 401 Unauthorized response when connecting #132

Open
nicktgn opened this issue Jul 9, 2023 · 1 comment
Open

Handle 401 Unauthorized response when connecting #132

nicktgn opened this issue Jul 9, 2023 · 1 comment

Comments

@nicktgn
Copy link

nicktgn commented Jul 9, 2023

I there a way to intercept and handle any specific server responses like 401 Unauthorized when connecting to websocket using ws.Start() or ws.StartOrFail().

I was trying to use ws.StartOrFail() but it just throws some generic error Unable to connect to the remote server that doesn't have any information about the reason for the error.

Thanks. Would appreciate any help.

@Marfusios
Copy link
Owner

Marfusios commented Aug 5, 2023

Hey, sorry for the late response.
The original exception is wrapped by our WebsocketException.
So check ex.InnerException, it should give you what you need.
This stands for ws.StartOrFail().

If you want to use the background method ws.Start(), you can follow something like this:

ws.DisconnectionHappened.Subscribe(info => {
    if(info.Exception is MyException myEx && myEx.Code == "401") {
        // stop reconnection
        info.CancelReconnection = true;
    }                    
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants