Skip to content

Commit 5773b8e

Browse files
authored
Update HttpException to display inner-errors on the HttpException.Message for better debugging (#2059)
Update HttpException.cs
1 parent 3475bd8 commit 5773b8e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Discord.Net.Core/Net/HttpException.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class HttpException : Exception
4949
/// <param name="discordCode">The Discord status code returned.</param>
5050
/// <param name="reason">The reason behind the exception.</param>
5151
public HttpException(HttpStatusCode httpCode, IRequest request, DiscordErrorCode? discordCode = null, string reason = null, DiscordJsonError[] errors = null)
52-
: base(CreateMessage(httpCode, (int?)discordCode, reason))
52+
: base(CreateMessage(httpCode, (int?)discordCode, reason, errors))
5353
{
5454
HttpCode = httpCode;
5555
Request = request;
@@ -58,8 +58,8 @@ public HttpException(HttpStatusCode httpCode, IRequest request, DiscordErrorCode
5858
Errors = errors?.ToImmutableArray() ?? ImmutableArray<DiscordJsonError>.Empty;
5959
}
6060

61-
private static string CreateMessage(HttpStatusCode httpCode, int? discordCode = null, string reason = null)
62-
{
61+
private static string CreateMessage(HttpStatusCode httpCode, int? discordCode = null, string reason = null, DiscordJsonError[] errors = null)
62+
{
6363
string msg;
6464
if (discordCode != null && discordCode != 0)
6565
{
@@ -75,6 +75,16 @@ private static string CreateMessage(HttpStatusCode httpCode, int? discordCode =
7575
else
7676
msg = $"The server responded with error {(int)httpCode}: {httpCode}";
7777
}
78+
79+
if (errors?.Length > 0)
80+
{
81+
msg += "\nInner Errors:";
82+
foreach (var error in errors)
83+
if (error.Errors?.Count > 0)
84+
foreach (var innerError in error.Errors)
85+
msg += $"\n{innerError.Code}: {innerError.Message}";
86+
}
87+
7888
return msg;
7989
}
8090
}

0 commit comments

Comments
 (0)