From f8d0fb2f4b209e2bea669c3f9a43f75adf91e6d7 Mon Sep 17 00:00:00 2001 From: Ske Date: Sun, 8 Mar 2020 10:55:47 +0100 Subject: [PATCH] Properly ignore invalid server-side data when executing webhooks --- PluralKit.Bot/Services/WebhookExecutorService.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/PluralKit.Bot/Services/WebhookExecutorService.cs b/PluralKit.Bot/Services/WebhookExecutorService.cs index ecfb43a5..37dd609c 100644 --- a/PluralKit.Bot/Services/WebhookExecutorService.cs +++ b/PluralKit.Bot/Services/WebhookExecutorService.cs @@ -75,11 +75,18 @@ namespace PluralKit.Bot timerCtx.Dispose(); 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 - throw new WebhookExecutionErrorOnDiscordsEnd(); - var responseJson = JsonConvert.DeserializeObject(responseString); + JObject responseJson; + try + { + responseJson = JsonConvert.DeserializeObject(responseString); + } + catch (JsonReaderException) + { + // Sometimes we get invalid JSON from the server, just ignore all of it + throw new WebhookExecutionErrorOnDiscordsEnd(); + } + if (responseJson.ContainsKey("code")) { var errorCode = responseJson["code"].Value();