diff --git a/NetCord/Gateway/GatewayClient.cs b/NetCord/Gateway/GatewayClient.cs index 4977541e..203c4dbb 100644 --- a/NetCord/Gateway/GatewayClient.cs +++ b/NetCord/Gateway/GatewayClient.cs @@ -5,6 +5,7 @@ using NetCord.Gateway.WebSockets; using NetCord.Logging; +using WebSocketException = System.Net.WebSockets.WebSocketException; using WebSocketCloseStatus = System.Net.WebSockets.WebSocketCloseStatus; namespace NetCord.Gateway; @@ -916,8 +917,19 @@ private ValueTask SendIdentifyAsync(ConnectionState connectionState, PresencePro /// public async ValueTask StartAsync(PresenceProperties? presence = null, CancellationToken cancellationToken = default) { - var connectionState = await StartAsync(new State(), cancellationToken).ConfigureAwait(false); - await SendIdentifyAsync(connectionState, presence, cancellationToken).ConfigureAwait(false); + try + { + var connectionState = await StartAsync(new State(), cancellationToken).ConfigureAwait(false); + await SendIdentifyAsync(connectionState, presence, cancellationToken).ConfigureAwait(false); + } + catch (WebSocketException ex) + { + Log(LogLevel.Error, null, ex, static (s, e) => + { + return $"An error occurred while starting the gateway client.{Environment.NewLine}{e}"; + }); + throw; + } } /// @@ -929,8 +941,19 @@ public async ValueTask StartAsync(PresenceProperties? presence = null, Cancellat /// public async ValueTask ResumeAsync(string sessionId, int sequenceNumber, CancellationToken cancellationToken = default) { - var connectionState = await StartAsync(new State(), cancellationToken).ConfigureAwait(false); - await TryResumeAsync(connectionState, SessionId = sessionId, SequenceNumber = sequenceNumber, cancellationToken).ConfigureAwait(false); + try + { + var connectionState = await StartAsync(new State(), cancellationToken).ConfigureAwait(false); + await TryResumeAsync(connectionState, SessionId = sessionId, SequenceNumber = sequenceNumber, cancellationToken).ConfigureAwait(false); + } + catch (WebSocketException ex) + { + Log(LogLevel.Error, null, ex, static (s, e) => + { + return $"An error occurred while resuming.{Environment.NewLine}{e}"; + }); + throw; + } } private protected override bool Reconnect(WebSocketCloseStatus? status, string? description)