Background and motivation
When customers connect to the Azure Web PubSub service using ClientWebSocket, there is a need to check if the connection failure is reconnectable or not. For example, if the HTTP upgrade request returns 400, this WebSocket connection is not reconnectable, while when the HTTP upgrade request returns 5xx, this might be caused by intermittent network issues and it is reconnectable. However, in the current design
|
throw new WebSocketException(WebSocketError.NotAWebSocket, SR.Format(SR.net_WebSockets_Connect101Expected, (int)response.StatusCode)); |
, the WebSocketException simply throws
WebSocketError.NotAWebSocket which makes it hard for customers to differentiate from different scenarios. Customers have to parse the
net_WebSockets_Connect101Expected string to get out the status code...
API Proposal
namespace System.Net.WebSockets
{
public sealed class WebSocketException : Win32Exception
{
public HttpResponseMessage UpgradeResponse { get; }
}
}
API Usage
try {
// Start the WebSocket connection
} catch (WebSocketException e) {
if (e.UpgradeResponse.StatusCode >= 500) {
// Try reconnecting...
}
}
Alternative Designs
No response
Risks
No response
Background and motivation
When customers connect to the Azure Web PubSub service using
ClientWebSocket, there is a need to check if the connection failure is reconnectable or not. For example, if the HTTP upgrade request returns 400, this WebSocket connection is not reconnectable, while when the HTTP upgrade request returns 5xx, this might be caused by intermittent network issues and it is reconnectable. However, in the current designruntime/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs
Line 149 in 2cbc071
WebSocketError.NotAWebSocketwhich makes it hard for customers to differentiate from different scenarios. Customers have to parse thenet_WebSockets_Connect101Expectedstring to get out the status code...API Proposal
API Usage
Alternative Designs
No response
Risks
No response