From 078b5a5bcd93d58ebad0b6ddd5657341657a771e Mon Sep 17 00:00:00 2001 From: spiral Date: Sat, 26 Feb 2022 16:28:28 -0500 Subject: [PATCH] feat: log error when globally ratelimited --- Myriad/Rest/BaseRestClient.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Myriad/Rest/BaseRestClient.cs b/Myriad/Rest/BaseRestClient.cs index 0db51a59..8877027b 100644 --- a/Myriad/Rest/BaseRestClient.cs +++ b/Myriad/Rest/BaseRestClient.cs @@ -191,7 +191,7 @@ public class BaseRestClient: IAsyncDisposable catch (Exception exc) { _logger.Error(exc, "HTTP error: {RequestMethod} {RequestUrl}", request.Method, - request.RequestUri); + CleanForLogging(request.RequestUri!)); // kill the running thread // 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); 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); _logger.Warning("Discord API error: {DiscordErrorCode} {DiscordErrorMessage}", apiError.Code, apiError.Message);