Skip to content

Commit

Permalink
Merge pull request #77 from aksio-insurtech:fix/exceptions
Browse files Browse the repository at this point in the history
Exception handling for JSON serializer + outputting error to console if any
  • Loading branch information
einari authored Dec 13, 2023
2 parents 18e74eb + 5caf8d3 commit 31ad57b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Source/DotNET/CQRS/Queries/ClientObservable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ public async Task HandleConnection(ActionExecutingContext context, JsonOptions j
subscription = _subject.Subscribe(async _ =>
{
queryResult.Data = _!;
var message = JsonSerializer.SerializeToUtf8Bytes(queryResult, jsonOptions.JsonSerializerOptions);
try
{
var message = JsonSerializer.SerializeToUtf8Bytes(queryResult, jsonOptions.JsonSerializerOptions);
await webSocket.SendAsync(message, WebSocketMessageType.Text, true, CancellationToken.None);
message = null!;
}
catch
catch (Exception ex)
{
Console.Error.WriteLine($"Error sending message to client: {ex.Message}\n{ex.StackTrace}");
subscription?.Dispose();
ClientDisconnected?.Invoke();
}
Expand Down

0 comments on commit 31ad57b

Please sign in to comment.