Update HttpException to display inner-errors on the HttpException.Message for better debugging (#2059)
Update HttpException.cs
This commit is contained in:
@@ -49,7 +49,7 @@ namespace Discord.Net
|
|||||||
/// <param name="discordCode">The Discord status code returned.</param>
|
/// <param name="discordCode">The Discord status code returned.</param>
|
||||||
/// <param name="reason">The reason behind the exception.</param>
|
/// <param name="reason">The reason behind the exception.</param>
|
||||||
public HttpException(HttpStatusCode httpCode, IRequest request, DiscordErrorCode? discordCode = null, string reason = null, DiscordJsonError[] errors = null)
|
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;
|
HttpCode = httpCode;
|
||||||
Request = request;
|
Request = request;
|
||||||
@@ -58,8 +58,8 @@ namespace Discord.Net
|
|||||||
Errors = errors?.ToImmutableArray() ?? ImmutableArray<DiscordJsonError>.Empty;
|
Errors = errors?.ToImmutableArray() ?? ImmutableArray<DiscordJsonError>.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;
|
string msg;
|
||||||
if (discordCode != null && discordCode != 0)
|
if (discordCode != null && discordCode != 0)
|
||||||
{
|
{
|
||||||
@@ -75,6 +75,16 @@ namespace Discord.Net
|
|||||||
else
|
else
|
||||||
msg = $"The server responded with error {(int)httpCode}: {httpCode}";
|
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;
|
return msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user