mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-14 09:40:10 +00:00
Ignore weirdly formatted server errors too
This commit is contained in:
parent
2354e7fd74
commit
456fe8f7af
1 changed files with 6 additions and 2 deletions
|
|
@ -70,8 +70,12 @@ namespace PluralKit.Bot
|
||||||
using var response = await _client.PostAsync($"{DiscordConfig.APIUrl}webhooks/{webhook.Id}/{webhook.Token}?wait=true", mfd);
|
using var response = await _client.PostAsync($"{DiscordConfig.APIUrl}webhooks/{webhook.Id}/{webhook.Token}?wait=true", mfd);
|
||||||
timerCtx.Dispose();
|
timerCtx.Dispose();
|
||||||
|
|
||||||
// TODO: are there cases where an error won't also return a parseable JSON object?
|
var responseString = await response.Content.ReadAsStringAsync();
|
||||||
var responseJson = JsonConvert.DeserializeObject<JObject>(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<JObject>(responseString);
|
||||||
if (responseJson.ContainsKey("code"))
|
if (responseJson.ContainsKey("code"))
|
||||||
{
|
{
|
||||||
var errorCode = responseJson["code"].Value<int>();
|
var errorCode = responseJson["code"].Value<int>();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue