PluralKit/Myriad/Rest/Exceptions/DiscordRequestException.cs

71 lines
2.6 KiB
C#
Raw Normal View History

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