From 456fe8f7afbea380e1e0b8aaf338f2518d362f84 Mon Sep 17 00:00:00 2001 From: Ske Date: Wed, 19 Feb 2020 01:00:23 +0100 Subject: [PATCH] Ignore weirdly formatted server errors too --- PluralKit.Bot/Services/WebhookExecutorService.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/PluralKit.Bot/Services/WebhookExecutorService.cs b/PluralKit.Bot/Services/WebhookExecutorService.cs index 21f0eaaf..cfbd4155 100644 --- a/PluralKit.Bot/Services/WebhookExecutorService.cs +++ b/PluralKit.Bot/Services/WebhookExecutorService.cs @@ -70,8 +70,12 @@ namespace PluralKit.Bot using var response = await _client.PostAsync($"{DiscordConfig.APIUrl}webhooks/{webhook.Id}/{webhook.Token}?wait=true", mfd); timerCtx.Dispose(); - // TODO: are there cases where an error won't also return a parseable JSON object? - var responseJson = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); + var responseString = await response.Content.ReadAsStringAsync(); + if (responseString.StartsWith("<")) + // if the response starts with a < it's probably a CloudFlare error or similar, so just force-break + response.EnsureSuccessStatusCode(); + + var responseJson = JsonConvert.DeserializeObject(responseString); if (responseJson.ContainsKey("code")) { var errorCode = responseJson["code"].Value();