Skip to content

Commit

Permalink
can we log errors?
Browse files Browse the repository at this point in the history
  • Loading branch information
juuwel committed May 28, 2024
1 parent a559127 commit 6b95429
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Tests/WebSocketTestClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json;
using api.Events.Global;
using lib;
using Websocket.Client;

Expand All @@ -12,12 +13,20 @@ public class WebSocketTestClient
public WebSocketTestClient(string? url = null)
{
Client = url == null ? new WebsocketClient(new Uri("ws://localhost:" + (Environment.GetEnvironmentVariable("FULLSTACK_API_PORT") ?? "8181"))) : new WebsocketClient(new Uri(url));
Client.MessageReceived.Subscribe((Action<ResponseMessage>) (msg =>
Client.MessageReceived.Subscribe(msg =>
{
BaseDto baseDto = JsonSerializer.Deserialize<BaseDto>(msg.Text);

if (baseDto.eventType == "ServerSendsError")
{
var error = JsonSerializer.Deserialize<ServerSendsErrorMessage>(msg.Text);
throw new Exception(error!.Error);
}


lock (ReceivedMessages)
ReceivedMessages.Add(baseDto);
}));
});
}

public async Task<WebSocketTestClient> ConnectAsync()
Expand Down

0 comments on commit 6b95429

Please sign in to comment.