Improved discord HTTP exceptions

This commit is contained in:
RogueException
2017-01-24 11:40:08 -04:00
parent b76c744447
commit 7ef48c5ce5
4 changed files with 43 additions and 17 deletions

View File

@@ -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;
}
}
}