Skip to content

Commit

Permalink
Merge pull request #322 from graphql-dotnet/swallow-pns-exceptions
Browse files Browse the repository at this point in the history
catch PlatformNotSupportedException for unsupported Options properties
  • Loading branch information
rose-a authored Jan 7, 2021
2 parents 5356743 + 14f30c9 commit a07d924
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/GraphQL.Client/Websocket/GraphQLHttpWebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,26 @@ public Task InitializeWebSocket()
#else
_clientWebSocket = new ClientWebSocket();
_clientWebSocket.Options.AddSubProtocol("graphql-ws");
if(!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Create("BROWSER")))

// the following properties are not supported in Blazor WebAssembly and throw a PlatformNotSupportedException error when accessed
try
{
// the following properties are not supported in Blazor WebAssembly and throw a PlatformNotSupportedException error when accessed
_clientWebSocket.Options.ClientCertificates = ((HttpClientHandler)Options.HttpMessageHandler).ClientCertificates;
}
catch (PlatformNotSupportedException)
{
Debug.WriteLine("property 'ClientWebSocketOptions.ClientCertificates' not supported by current platform");
}

try
{
_clientWebSocket.Options.UseDefaultCredentials = ((HttpClientHandler)Options.HttpMessageHandler).UseDefaultCredentials;
}
catch (PlatformNotSupportedException)
{
Debug.WriteLine("Property 'ClientWebSocketOptions.UseDefaultCredentials' not supported by current platform");
}

Options.ConfigureWebsocketOptions(_clientWebSocket.Options);
#endif
return _initializeWebSocketTask = ConnectAsync(_internalCancellationToken);
Expand Down

0 comments on commit a07d924

Please sign in to comment.