/
HttpException.cs
42 lines (39 loc) · 1.38 KB
/
HttpException.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Net;
namespace Discord.Net
{
public class HttpException : Exception
{
public HttpStatusCode HttpCode { get; }
public int? DiscordCode { get; }
public string Reason { get; }
public IRequest Request { get; }
public HttpException(HttpStatusCode httpCode, IRequest request, int? discordCode = null, string reason = null)
: base(CreateMessage(httpCode, discordCode, reason))
{
HttpCode = httpCode;
Request = request;
DiscordCode = discordCode;
Reason = reason;
}
private static string CreateMessage(HttpStatusCode httpCode, int? discordCode = null, string reason = null)
{
string msg;
if (discordCode != null && discordCode != 0)
{
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;
}
}
}