From d417a0594949b8cb50037d2755050e4b30e8f86f Mon Sep 17 00:00:00 2001 From: Nikita Petko Date: Tue, 25 Jan 2022 23:36:02 +0000 Subject: [PATCH] Update HttpException.cs Make it also display the inner-errors in the HttpException message --- src/Discord.Net.Core/Net/HttpException.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net.Core/Net/HttpException.cs b/src/Discord.Net.Core/Net/HttpException.cs index 07551f0e7..b026bc6f1 100644 --- a/src/Discord.Net.Core/Net/HttpException.cs +++ b/src/Discord.Net.Core/Net/HttpException.cs @@ -49,7 +49,7 @@ namespace Discord.Net /// The Discord status code returned. /// The reason behind the exception. public HttpException(HttpStatusCode httpCode, IRequest request, DiscordErrorCode? discordCode = null, string reason = null, DiscordJsonError[] errors = null) - : base(CreateMessage(httpCode, (int?)discordCode, reason)) + : base(CreateMessage(httpCode, (int?)discordCode, reason, errors)) { HttpCode = httpCode; Request = request; @@ -58,8 +58,8 @@ namespace Discord.Net Errors = errors?.ToImmutableArray() ?? ImmutableArray.Empty; } - private static string CreateMessage(HttpStatusCode httpCode, int? discordCode = null, string reason = null) - { + private static string CreateMessage(HttpStatusCode httpCode, int? discordCode = null, string reason = null, DiscordJsonError[] errors = null) + { string msg; if (discordCode != null && discordCode != 0) { @@ -75,6 +75,16 @@ namespace Discord.Net else msg = $"The server responded with error {(int)httpCode}: {httpCode}"; } + + if (errors?.Length > 0) + { + msg += "\nInner Errors:"; + foreach (var error in errors) + if (error.Errors?.Count > 0) + foreach (var innerError in error.Errors) + msg += $"\n{innerError.Code}: {innerError.Message}"; + } + return msg; } }