if (response.StatusCode != HttpStatusCode.SwitchingProtocols)
{
- throw new WebSocketException(SR.Format(SR.net_WebSockets_Connect101Expected, (int) response.StatusCode));
+ throw new WebSocketException(WebSocketError.NotAWebSocket, SR.Format(SR.net_WebSockets_Connect101Expected, (int) response.StatusCode));
}
// The Connection, Upgrade, and SecWebSocketAccept headers are required and with specific values.
{
throw;
}
- throw new WebSocketException(SR.net_webstatus_ConnectFailure, exc);
+ throw new WebSocketException(WebSocketError.Faulted, SR.net_webstatus_ConnectFailure, exc);
}
finally
{
string[] array = (string[])values;
if (array.Length != 1 || !string.Equals(array[0], expectedValue, StringComparison.OrdinalIgnoreCase))
{
- throw new WebSocketException(SR.Format(SR.net_WebSockets_InvalidResponseHeader, name, string.Join(", ", array)));
+ throw new WebSocketException(WebSocketError.HeaderError, SR.Format(SR.net_WebSockets_InvalidResponseHeader, name, string.Join(", ", array)));
}
}
- private static void ThrowConnectFailure() => throw new WebSocketException(SR.net_webstatus_ConnectFailure);
+ private static void ThrowConnectFailure() => throw new WebSocketException(WebSocketError.Faulted, SR.net_webstatus_ConnectFailure);
}
}
{
WebErrorStatus status = RTWebSocketError.GetStatus(ex.HResult);
var inner = new Exception(status.ToString(), ex);
- WebSocketException wex = new WebSocketException(SR.net_webstatus_ConnectFailure, inner);
+ WebSocketException wex = new WebSocketException(WebSocketError.Faulted, SR.net_webstatus_ConnectFailure, inner);
if (NetEventSource.IsEnabled) NetEventSource.Error(_webSocket, wex);
throw wex;
}
Assert.Equal(ResourceHelper.GetExceptionMessage("net_webstatus_ConnectFailure"), ex.Message);
- Assert.Equal(WebSocketError.Success, ex.WebSocketErrorCode);
+ if (PlatformDetection.IsNetCore) // bug fix in netcoreapp: https://github.com/dotnet/corefx/pull/35960
+ {
+ Assert.Equal(WebSocketError.Faulted, ex.WebSocketErrorCode);
+ }
Assert.Equal(WebSocketState.Closed, cws.State);
}
}
Assert.Equal(
ResourceHelper.GetExceptionMessage("net_webstatus_ConnectFailure"),
ex.Message);
- Assert.Equal(WebSocketError.Success, ex.WebSocketErrorCode);
+ if (PlatformDetection.IsNetCore) // bug fix in netcoreapp: https://github.com/dotnet/corefx/pull/35960
+ {
+ Assert.Equal(WebSocketError.Faulted, ex.WebSocketErrorCode);
+ }
Assert.Equal(WebSocketState.Closed, cws.State);
}
}
server = new Uri(string.Format("ws://{0}", Guid.NewGuid().ToString()));
exceptionMessage = ResourceHelper.GetExceptionMessage("net_webstatus_ConnectFailure");
- yield return new object[] { server, exceptionMessage };
+ yield return new object[] { server, exceptionMessage, WebSocketError.Faulted };
}
// Known server but not a real websocket endpoint.
var ub = new UriBuilder("ws", server.Host, server.Port, server.PathAndQuery);
exceptionMessage = ResourceHelper.GetExceptionMessage("net_WebSockets_Connect101Expected", (int) HttpStatusCode.OK);
- yield return new object[] { ub.Uri, exceptionMessage };
+ yield return new object[] { ub.Uri, exceptionMessage, WebSocketError.NotAWebSocket };
}
}
}
[OuterLoop] // TODO: Issue #11345
[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(UnavailableWebSocketServers))]
- public async Task ConnectAsync_NotWebSocketServer_ThrowsWebSocketExceptionWithMessage(Uri server, string exceptionMessage)
+ public async Task ConnectAsync_NotWebSocketServer_ThrowsWebSocketExceptionWithMessage(Uri server, string exceptionMessage, WebSocketError errorCode)
{
using (var cws = new ClientWebSocket())
{
WebSocketException ex = await Assert.ThrowsAsync<WebSocketException>(() =>
cws.ConnectAsync(server, cts.Token));
- Assert.Equal(WebSocketError.Success, ex.WebSocketErrorCode);
+ if (PlatformDetection.IsNetCore && !PlatformDetection.IsUap) // bug fix in netcoreapp: https://github.com/dotnet/corefx/pull/35960
+ {
+ Assert.Equal(errorCode, ex.WebSocketErrorCode);
+ }
Assert.Equal(WebSocketState.Closed, cws.State);
// .NET Framework and UAP implmentations have different exception message from .NET Core.
WebSocketException ex = await Assert.ThrowsAsync<WebSocketException>(() =>
cws.ConnectAsync(ub.Uri, cts.Token));
- Assert.Equal(WebSocketError.Success, ex.WebSocketErrorCode);
+ if (PlatformDetection.IsNetCore) // bug fix in netcoreapp: https://github.com/dotnet/corefx/pull/35960
+ {
+ Assert.Equal(WebSocketError.Faulted, ex.WebSocketErrorCode);
+ }
Assert.Equal(WebSocketState.Closed, cws.State);
Assert.Equal(ResourceHelper.GetExceptionMessage("net_webstatus_ConnectFailure"), ex.Message);
}
validStatesText = string.Join(", ", validStates);
}
- throw new WebSocketException(SR.Format(SR.net_WebSockets_InvalidState, state, validStatesText));
+ throw new WebSocketException(WebSocketError.InvalidState, SR.Format(SR.net_WebSockets_InvalidState, state, validStatesText));
}
protected static bool IsStateTerminal(WebSocketState state) =>
[InlineData(WebSocketState.Open, new WebSocketState[] { WebSocketState.Aborted, WebSocketState.CloseSent })]
public static void ThrowOnInvalidState_ThrowsIfNotInValidList(WebSocketState state, WebSocketState[] validStates)
{
- Assert.Throws<WebSocketException>(() => ExposeProtectedWebSocket.ThrowOnInvalidState(state, validStates));
+ WebSocketException wse = Assert.Throws<WebSocketException>(() => ExposeProtectedWebSocket.ThrowOnInvalidState(state, validStates));
+ if (PlatformDetection.IsNetCore) // bug fix in netcoreapp: https://github.com/dotnet/corefx/pull/35960
+ {
+ Assert.Equal(WebSocketError.InvalidState, wse.WebSocketErrorCode);
+ }
}
[Theory]