From ec305c38a7c9a1fe1c3505be963877e3baaddff4 Mon Sep 17 00:00:00 2001 From: Twinki Date: Sun, 17 Dec 2023 19:17:27 -0500 Subject: [PATCH] Catch discord dotnet http exceptions in Schedule service (#56) --- .../Services/Hosted/GuildEventScheduleService.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Miha.Discord/Services/Hosted/GuildEventScheduleService.cs b/src/Miha.Discord/Services/Hosted/GuildEventScheduleService.cs index 6484cc8..57ecb68 100644 --- a/src/Miha.Discord/Services/Hosted/GuildEventScheduleService.cs +++ b/src/Miha.Discord/Services/Hosted/GuildEventScheduleService.cs @@ -3,6 +3,7 @@ using Discord; using Discord.Addons.Hosting; using Discord.Addons.Hosting.Util; +using Discord.Net; using Discord.WebSocket; using Humanizer; using Microsoft.Extensions.Logging; @@ -53,7 +54,18 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) while (!stoppingToken.IsCancellationRequested) { - await PostWeeklyScheduleAsync(); + try + { + await PostWeeklyScheduleAsync(); + } + catch (HttpException e) + { + _logger.LogWarning(e, "Discord dotnet http exception caught, likely caused by rate-limits, waiting a few minutes before continuing"); + + await Task.Delay(TimeSpan.FromMinutes(3), stoppingToken); + + continue; + } var utcNow = _easternStandardZonedClock.GetCurrentInstant().ToDateTimeUtc(); var nextUtc = _cron.GetNextOccurrence(DateTimeOffset.UtcNow, _easternStandardZonedClock.GetTimeZoneInfo());