PluralKit/Myriad/Rest/Exceptions/DiscordRequestException.cs

83 lines
2.7 KiB
C#
Raw Normal View History

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