Skip to content

Commit 82af731

Browse files
committed
Excluded GraphQLWebSocketMiddleware from exception stack trace if request is not a Web Socket
1 parent 0023760 commit 82af731

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,4 @@
235235
### Unreleased
236236

237237
* Added `TimeOnly` GraphQL type
238+
* Excluded `GraphQLWebSocketMiddleware` from exception stack trace if request not a Web Socket

src/FSharp.Data.GraphQL.Server.AspNetCore/GraphQLWebsocketMiddleware.fs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -346,25 +346,26 @@ type GraphQLWebSocketMiddleware<'Root>
346346
return Result.Error <| "{nameof ConnectionInit} timeout"
347347
}
348348

349-
member _.InvokeAsync (ctx : HttpContext) = task {
349+
member _.InvokeAsync (ctx : HttpContext) =
350350
if not (ctx.Request.Path = endpointUrl) then
351-
do! next.Invoke (ctx)
351+
next.Invoke (ctx)
352352
else if ctx.WebSockets.IsWebSocketRequest then
353-
use! socket = ctx.WebSockets.AcceptWebSocketAsync ("graphql-transport-ws")
354-
let! connectionInitResult = socket |> waitForConnectionInitAndRespondToClient
355-
match connectionInitResult with
356-
| Result.Error errMsg -> logger.LogWarning errMsg
357-
| Ok _ ->
358-
let longRunningCancellationToken =
359-
(CancellationTokenSource
360-
.CreateLinkedTokenSource(ctx.RequestAborted, applicationLifetime.ApplicationStopping)
361-
.Token)
362-
longRunningCancellationToken.Register (fun _ -> (socket |> tryToGracefullyCloseSocketWithDefaultBehavior).Wait ())
363-
|> ignore
364-
try
365-
do! socket |> handleMessages longRunningCancellationToken ctx
366-
with ex ->
367-
logger.LogError (ex, "Cannot handle WebSocket message.")
353+
task {
354+
use! socket = ctx.WebSockets.AcceptWebSocketAsync ("graphql-transport-ws")
355+
let! connectionInitResult = socket |> waitForConnectionInitAndRespondToClient
356+
match connectionInitResult with
357+
| Result.Error errMsg -> logger.LogWarning errMsg
358+
| Ok _ ->
359+
let longRunningCancellationToken =
360+
(CancellationTokenSource
361+
.CreateLinkedTokenSource(ctx.RequestAborted, applicationLifetime.ApplicationStopping)
362+
.Token)
363+
longRunningCancellationToken.Register (fun _ -> (socket |> tryToGracefullyCloseSocketWithDefaultBehavior).Wait ())
364+
|> ignore
365+
try
366+
do! socket |> handleMessages longRunningCancellationToken ctx
367+
with ex ->
368+
logger.LogError (ex, "Cannot handle WebSocket message.")
369+
}
368370
else
369-
do! next.Invoke (ctx)
370-
}
371+
next.Invoke (ctx)

0 commit comments

Comments
 (0)