feat: log error when globally ratelimited

This commit is contained in:
spiral 2022-02-26 16:28:28 -05:00
parent 32a73eef09
commit 078b5a5bcd
No known key found for this signature in database
GPG Key ID: 244A11E4B0BCF40E

View File

@ -191,7 +191,7 @@ public class BaseRestClient: IAsyncDisposable
catch (Exception exc) catch (Exception exc)
{ {
_logger.Error(exc, "HTTP error: {RequestMethod} {RequestUrl}", request.Method, _logger.Error(exc, "HTTP error: {RequestMethod} {RequestUrl}", request.Method,
request.RequestUri); CleanForLogging(request.RequestUri!));
// kill the running thread // kill the running thread
// in PluralKit.Bot, this error is ignored in "IsOurProblem" (PluralKit.Bot/Utils/MiscUtils.cs) // in PluralKit.Bot, this error is ignored in "IsOurProblem" (PluralKit.Bot/Utils/MiscUtils.cs)
@ -232,6 +232,18 @@ public class BaseRestClient: IAsyncDisposable
var apiError = TryParseApiError(body); var apiError = TryParseApiError(body);
if (apiError != null) if (apiError != null)
{ {
string? xRateLimitScope = "";
try
{
var ratelimitHeader = response.Headers.FirstOrDefault(x => x.Key == "x-ratelimit-scope");
xRateLimitScope = ratelimitHeader.Value.FirstOrDefault();
if (xRateLimitScope == "global")
_logger.Error("We are globally ratelimited!");
}
catch (Exception) { }
using var __ = LogContext.PushProperty("RatelimitScope", xRateLimitScope);
using var _ = LogContext.PushProperty("DiscordErrorBody", body); using var _ = LogContext.PushProperty("DiscordErrorBody", body);
_logger.Warning("Discord API error: {DiscordErrorCode} {DiscordErrorMessage}", apiError.Code, _logger.Warning("Discord API error: {DiscordErrorCode} {DiscordErrorMessage}", apiError.Code,
apiError.Message); apiError.Message);