From 8ea02dae81417e5b8832c95676d03479f89b0122 Mon Sep 17 00:00:00 2001 From: Ske Date: Tue, 12 May 2020 21:23:05 +0200 Subject: [PATCH] Add more error reporting for Discord errors --- PluralKit.Bot/Bot.cs | 12 ++++++++++-- PluralKit.Bot/Utils/MiscUtils.cs | 5 ----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/PluralKit.Bot/Bot.cs b/PluralKit.Bot/Bot.cs index 4b26558a..77b78c00 100644 --- a/PluralKit.Bot/Bot.cs +++ b/PluralKit.Bot/Bot.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Net.WebSockets; using System.Threading; @@ -129,8 +130,6 @@ namespace PluralKit.Bot { // Make this beforehand so we can access the event ID for logging var sentryEvent = new SentryEvent(exc); - if (exc is BadRequestException bre) - sentryEvent.SetExtra("errors", MiscUtils.ExtractError(bre)); _logger.Error(exc, "Exception in bot event handler (Sentry ID: {SentryEventId})", sentryEvent.EventId); @@ -140,6 +139,15 @@ namespace PluralKit.Bot // Report error to Sentry // This will just no-op if there's no URL set var sentryScope = serviceScope.Resolve(); + + // Add some specific info about Discord error responses, as a breadcrumb + if (exc is BadRequestException bre) + sentryScope.AddBreadcrumb(bre.WebResponse.Response, "response.error", data: new Dictionary(bre.WebResponse.Headers)); + if (exc is NotFoundException nfe) + sentryScope.AddBreadcrumb(nfe.WebResponse.Response, "response.error", data: new Dictionary(nfe.WebResponse.Headers)); + if (exc is UnauthorizedException ue) + sentryScope.AddBreadcrumb(ue.WebResponse.Response, "response.error", data: new Dictionary(ue.WebResponse.Headers)); + SentrySdk.CaptureEvent(sentryEvent, sentryScope); // Once we've sent it to Sentry, report it to the user (if we have permission to) diff --git a/PluralKit.Bot/Utils/MiscUtils.cs b/PluralKit.Bot/Utils/MiscUtils.cs index 4c610aca..b0c09f08 100644 --- a/PluralKit.Bot/Utils/MiscUtils.cs +++ b/PluralKit.Bot/Utils/MiscUtils.cs @@ -49,10 +49,5 @@ namespace PluralKit.Bot // This may expanded at some point. return true; } - - public static string ExtractError(BadRequestException e) - { - return e.WebResponse.Response; - } } } \ No newline at end of file