Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions NetCord/Gateway/GatewayClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -916,8 +917,19 @@ private ValueTask SendIdentifyAsync(ConnectionState connectionState, PresencePro
/// <returns></returns>
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<object?>(LogLevel.Error, null, ex, static (s, e) =>
{
return $"An error occurred while starting the gateway client.{Environment.NewLine}{e}";
});
throw;
}
}

/// <summary>
Expand All @@ -929,8 +941,19 @@ public async ValueTask StartAsync(PresenceProperties? presence = null, Cancellat
/// <returns></returns>
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<object?>(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)
Expand Down