Ignore CloudFlare error response parsing errors

This commit is contained in:
Ske 2020-05-07 23:59:05 +02:00
parent e9a271ef60
commit 53582997f0

View File

@ -5,6 +5,8 @@ using System.Threading.Tasks;
using DSharpPlus.Exceptions; using DSharpPlus.Exceptions;
using Newtonsoft.Json;
using Npgsql; using Npgsql;
using PluralKit.Core; using PluralKit.Core;
@ -20,9 +22,14 @@ namespace PluralKit.Bot
// otherwise we'd blow out our error reporting budget as soon as Discord takes a dump, or something. // otherwise we'd blow out our error reporting budget as soon as Discord takes a dump, or something.
// Discord server errors are *not our problem* // Discord server errors are *not our problem*
// TODO // TODO: DSharpPlus doesn't have a generic "HttpException" type and only special cases a couple response codes (that we don't need here)
// Doesn't seem to handle 500s in the library at all, I'm not sure what it does in case it receives one...
// if (e is DSharpPlus.Exceptions he && ((int) he.HttpCode) >= 500) return false; // if (e is DSharpPlus.Exceptions he && ((int) he.HttpCode) >= 500) return false;
// Occasionally Discord's API will Have A Bad Time and return a bunch of CloudFlare errors (in HTML format).
// The library tries to parse these HTML responses as JSON and crashes with a consistent exception message.
if (e is JsonReaderException jre && jre.Message == "Unexpected character encountered while parsing value: <. Path '', line 0, position 0.") return false;
// Webhook server errors are also *not our problem* // Webhook server errors are also *not our problem*
// (this includes rate limit errors, WebhookRateLimited is a subclass) // (this includes rate limit errors, WebhookRateLimited is a subclass)
if (e is WebhookExecutionErrorOnDiscordsEnd) return false; if (e is WebhookExecutionErrorOnDiscordsEnd) return false;