@@ -259,22 +259,26 @@ type GraphQLWebSocketMiddleware<'Root>
259
259
| ValueNone -> do ! ServerPong p |> sendMsg
260
260
| ClientPong p -> nameof ClientPong |> logMsgReceivedWithOptionalPayload p
261
261
| Subscribe ( id, query) ->
262
- nameof Subscribe |> logMsgWithIdReceived id
263
- if subscriptions |> GraphQLSubscriptionsManagement.isIdTaken id then
264
- do !
265
- let warningMsg : FormattableString = $" Subscriber for Id = '{id}' already exists"
266
- logger.LogWarning ( String.Format ( warningMsg.Format, " id" ), id)
267
- socket.CloseAsync (
268
- enum CustomWebSocketStatus.SubscriberAlreadyExists,
269
- warningMsg.ToString (),
270
- CancellationToken.None
271
- )
272
- else
273
- let variables = query.Variables |> Skippable.toOption
274
- let! planExecutionResult =
275
- let root = options.RootFactory httpContext
276
- options.SchemaExecutor.AsyncExecute ( query.Query, root, ?variables = variables)
277
- do ! planExecutionResult |> applyPlanExecutionResult id socket
262
+ try
263
+ nameof Subscribe |> logMsgWithIdReceived id
264
+ if subscriptions |> GraphQLSubscriptionsManagement.isIdTaken id then
265
+ do !
266
+ let warningMsg : FormattableString = $" Subscriber for Id = '{id}' already exists"
267
+ logger.LogWarning ( String.Format ( warningMsg.Format, " id" ), id)
268
+ socket.CloseAsync (
269
+ enum CustomWebSocketStatus.SubscriberAlreadyExists,
270
+ warningMsg.ToString (),
271
+ CancellationToken.None
272
+ )
273
+ else
274
+ let variables = query.Variables |> Skippable.toOption
275
+ let! planExecutionResult =
276
+ let root = options.RootFactory httpContext
277
+ options.SchemaExecutor.AsyncExecute ( query.Query, root, ?variables = variables)
278
+ do ! planExecutionResult |> applyPlanExecutionResult id socket
279
+ with ex ->
280
+ logger.LogError ( ex, " Unexpected error during subscription with id '{id}'" , id)
281
+ do ! sendMsg ( Error ( id, [ new Shared.NameValueLookup ([ ( " subscription" , " Unexpected error during subscription" :> obj ) ])]))
278
282
| ClientComplete id ->
279
283
" ClientComplete" |> logMsgWithIdReceived id
280
284
subscriptions
0 commit comments