Improved discord HTTP exceptions
This commit is contained in:
@@ -5,14 +5,36 @@ namespace Discord.Net
|
||||
{
|
||||
public class HttpException : Exception
|
||||
{
|
||||
public HttpStatusCode StatusCode { get; }
|
||||
public HttpStatusCode HttpCode { get; }
|
||||
public int? DiscordCode { get; }
|
||||
public string Reason { get; }
|
||||
|
||||
public HttpException(HttpStatusCode statusCode, string reason = null)
|
||||
: base($"The server responded with error {(int)statusCode} ({statusCode}){(reason != null ? $": \"{reason}\"" : "")}")
|
||||
public HttpException(HttpStatusCode httpCode, int? discordCode = null, string reason = null)
|
||||
: base(CreateMessage(httpCode, discordCode, reason))
|
||||
{
|
||||
StatusCode = statusCode;
|
||||
HttpCode = httpCode;
|
||||
DiscordCode = discordCode;
|
||||
Reason = reason;
|
||||
}
|
||||
|
||||
private static string CreateMessage(HttpStatusCode httpCode, int? discordCode = null, string reason = null)
|
||||
{
|
||||
string msg;
|
||||
if (discordCode != null)
|
||||
{
|
||||
if (reason != null)
|
||||
msg = $"The server responded with error {(int)discordCode}: {reason}";
|
||||
else
|
||||
msg = $"The server responded with error {(int)discordCode}: {httpCode}";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (reason != null)
|
||||
msg = $"The server responded with error {(int)httpCode}: {reason}";
|
||||
else
|
||||
msg = $"The server responded with error {(int)httpCode}: {httpCode}";
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user