-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
HttpClient and WebSockets don't provide HTTP error details #19405
Comments
@karelz - Do you know if there is someone we can talk to about validating this issue? We'd like to get an idea if this is something that the team would like to fix at all (regardless of timeline), or if it is something we can help with a PR. |
We are starting System.Net triage next Monday (see area list). It will likely drag till January -- the area is the largest (~20% of all corefx repo) and we lost our Linux/Mac expert recently. That said, we can always speed up ad-hoc triage of particular issues if there's interest. @dstuckims if you have proposal for the API change, please let us know. Naively it looks like a reasonable ask. |
Seems reasonable to me to expose some of those details somewhere, either on the exception that's thrown or on the ClientWebSocket instance itself. @davidsh and @CIPop should comment, though. |
Sounds like a good idea. |
In .NET 4.5 when ClientWebSocket.ConnectAsync fails like this it is actually possible to get the HTTP status code and description because the inner exception (which comes from HttpWebRequest) is a WebException and its Response property has an HttpResponse instance. If we could fabricate the same tree in the .NET Core codebase then the code I originally wrote on .NET 4.5 would work for .NET Core too! |
What is the exception on .NET Core today? |
With the WinHttp WebSocket implementation it's a WinHttpException (which is an internal only type) with no interesting details. With the Managed WebSocket implementation if the HTTP status line doesn't start with "HTTP/1.1 101 " (status code = 101, Switching Protocols) it simply throws a WebSocketException with a default message like this:
|
That's what I thought. Let's keep this issue to track an adaptation layer between
@karelz the Not very sure but it may still be valuable for the |
Next steps: We need a plan to:
|
What is the status of this? It's a pretty big blocker for Couchbase Lite .NET because we need to present information to the user about why their connection failed (for example, invalid credentials) or possibly retry the connection if we feel the error is transient. |
It is in Future milestone, so no promise when it will be addressed. |
I am also using the WebException to check if it's a transient TLS error (we get these allot secretly) Would really help to have those statuses back in some way or form, because when I get the error it's a direct result of a end user wanting to get some information from a external source (example starting a payment request) so I need to quickly retry any transient problem |
We are in need of this feature too. |
Same issue here. The behavior is not consistent between .NET and .NET Core. The following code throws different exceptions on the 2 frameworks:
Exception from .NET 462
Exception from .NET Core 2.0
As you can see, the exception from .NET Core does not indicate what is the problem is. As opposed to the exception from .NET 462, where the inner exception is the actual |
This has been obsoleted since we no longer use WinHTTP for System.Net.WebSockets.Client and use SocketsHttpHandler for the HTTP stack. |
@davidsh Even though the implementation changed to SocketHttpHandler, the main problem of not propagating an appropriate exception with the upgrade response still exits. See https://github.com/dotnet/corefx/blob/14435e14d39bf70697956535b8ac6c96b49e9cea/src/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs#L175 where it throws generic exception without any details. Should a new issue be opened tracking this issue ? |
Yes, please open up a new issue. Please be specific in terms of what additional information you would like to see propagated to the exception and under what conditions. |
I have a WebSocket service which can return error details in the HTTP response to a WebSocket upgrade request such as:
HTTP/1.1 404 Endpoint does not exist. TrackingId:71d07da7-8ace-4463-b764-1f76559aebd0_G2
When I use ClientWebSocket.ConnectAsync and it fails (expected) there's no way to get the HTTP StatusCode (e.g. 404) or the HTTP StatusDescription (e.g. "Endpoint does not exist. TrackingId:71d07da7-8ace-4463-b764-1f76559aebd0_G2").
The text was updated successfully, but these errors were encountered: