From 20789411f6673e0aca25918cd958a5e0ac5b8455 Mon Sep 17 00:00:00 2001 From: Ske Date: Sun, 8 Mar 2020 11:06:08 +0100 Subject: [PATCH] Cancel early when rate limited --- PluralKit.Bot/Services/WebhookExecutorService.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PluralKit.Bot/Services/WebhookExecutorService.cs b/PluralKit.Bot/Services/WebhookExecutorService.cs index 37dd609c..fb963d49 100644 --- a/PluralKit.Bot/Services/WebhookExecutorService.cs +++ b/PluralKit.Bot/Services/WebhookExecutorService.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; using System.Net.Http; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -74,6 +75,10 @@ namespace PluralKit.Bot using var response = await _client.PostAsync($"{DiscordConfig.APIUrl}webhooks/{webhook.Id}/{webhook.Token}?wait=true", mfd); timerCtx.Dispose(); + if (response.StatusCode == HttpStatusCode.TooManyRequests) + // Rate limits should be respected, we bail early + throw new WebhookExecutionErrorOnDiscordsEnd(); + var responseString = await response.Content.ReadAsStringAsync(); JObject responseJson;