2020-12-22 12:15:26 +00:00
|
|
|
using System.Net;
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace Myriad.Rest.Exceptions;
|
|
|
|
|
|
|
|
public class DiscordRequestException: Exception
|
2020-12-22 12:15:26 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
public DiscordRequestException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError)
|
2020-12-22 12:15:26 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
ResponseBody = responseBody;
|
|
|
|
Response = response;
|
|
|
|
ApiError = apiError;
|
|
|
|
}
|
2020-12-22 12:15:26 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public string ResponseBody { get; init; } = null!;
|
|
|
|
public HttpResponseMessage Response { get; init; } = null!;
|
2020-12-22 12:15:26 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public HttpStatusCode StatusCode => Response.StatusCode;
|
|
|
|
public int? ErrorCode => ApiError?.Code;
|
2020-12-22 12:15:26 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
internal DiscordApiError? ApiError { get; init; }
|
2020-12-22 12:15:26 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public override string Message =>
|
|
|
|
(ApiError?.Message ?? Response.ReasonPhrase ?? "") + (FormError != null ? $": {FormError}" : "");
|
2020-12-22 12:15:26 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public string? FormError => ApiError?.Errors?.ToString();
|
|
|
|
}
|
2020-12-22 12:15:26 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public class NotFoundException: DiscordRequestException
|
|
|
|
{
|
|
|
|
public NotFoundException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) : base(
|
|
|
|
response, responseBody, apiError)
|
|
|
|
{ }
|
|
|
|
}
|
2020-12-22 12:15:26 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public class UnauthorizedException: DiscordRequestException
|
|
|
|
{
|
|
|
|
public UnauthorizedException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) :
|
|
|
|
base(
|
2021-08-27 15:03:47 +00:00
|
|
|
response, responseBody, apiError)
|
2021-11-27 02:10:56 +00:00
|
|
|
{ }
|
|
|
|
}
|
2020-12-22 12:15:26 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public class ForbiddenException: DiscordRequestException
|
|
|
|
{
|
|
|
|
public ForbiddenException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) : base(
|
|
|
|
response, responseBody, apiError)
|
|
|
|
{ }
|
|
|
|
}
|
2020-12-22 12:15:26 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public class ConflictException: DiscordRequestException
|
|
|
|
{
|
|
|
|
public ConflictException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) : base(
|
|
|
|
response, responseBody, apiError)
|
|
|
|
{ }
|
|
|
|
}
|
2020-12-22 12:15:26 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public class BadRequestException: DiscordRequestException
|
|
|
|
{
|
|
|
|
public BadRequestException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) : base(
|
|
|
|
response, responseBody, apiError)
|
|
|
|
{ }
|
|
|
|
}
|
2020-12-22 12:15:26 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public class TooManyRequestsException: DiscordRequestException
|
|
|
|
{
|
|
|
|
public TooManyRequestsException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) :
|
|
|
|
base(response, responseBody, apiError)
|
|
|
|
{ }
|
|
|
|
}
|
2020-12-22 12:15:26 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public class UnknownDiscordRequestException: DiscordRequestException
|
|
|
|
{
|
|
|
|
public UnknownDiscordRequestException(HttpResponseMessage response, string responseBody,
|
|
|
|
DiscordApiError? apiError) : base(response, responseBody, apiError) { }
|
2020-12-22 12:15:26 +00:00
|
|
|
}
|