Skip to content

Commit 61373d7

Browse files
authored
Merge pull request #283 from bjorg/issue_280
check if running in WebAssembly instead of catching PlatformNotSupportedException
2 parents 3483e8e + 7fe7137 commit 61373d7

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/GraphQL.Client/Websocket/GraphQLHttpWebSocket.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -408,22 +408,12 @@ public Task InitializeWebSocket()
408408
#else
409409
_clientWebSocket = new ClientWebSocket();
410410
_clientWebSocket.Options.AddSubProtocol("graphql-ws");
411-
try
411+
if(!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Create("WEBASSEMBLY")))
412412
{
413+
// the following properties are not supported in Blazor WebAssembly and throw a PlatformNotSupportedException error when accessed
413414
_clientWebSocket.Options.ClientCertificates = ((HttpClientHandler)Options.HttpMessageHandler).ClientCertificates;
414-
}
415-
catch (PlatformNotSupportedException)
416-
{
417-
Debug.WriteLine("unable to set Options.ClientCertificates property; platform does not support it");
418-
}
419-
try
420-
{
421415
_clientWebSocket.Options.UseDefaultCredentials = ((HttpClientHandler)Options.HttpMessageHandler).UseDefaultCredentials;
422416
}
423-
catch (PlatformNotSupportedException)
424-
{
425-
Debug.WriteLine("unable to set Options.UseDefaultCredentials property; platform does not support it");
426-
}
427417
Options.ConfigureWebsocketOptions(_clientWebSocket.Options);
428418
#endif
429419
return _initializeWebSocketTask = ConnectAsync(_internalCancellationToken);
@@ -627,7 +617,7 @@ public void Complete()
627617

628618
/// <summary>
629619
/// Task to await the completion (a.k.a. disposal) of this websocket.
630-
/// </summary>
620+
/// </summary>
631621
/// Async disposal as recommended by Stephen Cleary (https://blog.stephencleary.com/2013/03/async-oop-6-disposal.html)
632622
public Task? Completion { get; private set; }
633623

0 commit comments

Comments
 (0)