Cancel early when rate limited

This commit is contained in:
Ske 2020-03-08 11:06:08 +01:00
parent f8d0fb2f4b
commit 20789411f6

View File

@ -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;