Foxchat.NET/Foxchat.Core/FoxchatError.cs

36 lines
1.5 KiB
C#
Raw Normal View History

2024-05-19 23:51:53 +02:00
using System.Net;
2024-05-14 14:50:01 +02:00
namespace Foxchat.Core;
2024-05-20 19:42:04 +02:00
public class FoxchatError(string message, Exception? inner = null) : Exception(message)
2024-05-14 14:50:01 +02:00
{
2024-05-20 19:42:04 +02:00
public Exception? Inner => inner;
public class DatabaseError(string message, Exception? inner = null) : FoxchatError(message, inner);
public class UnknownEntityError(Type entityType, Exception? inner = null) : FoxchatError($"Entity of type {entityType.Name} not found", inner);
2024-05-19 23:51:53 +02:00
}
public class ApiError(string message, HttpStatusCode? statusCode = null) : FoxchatError(message)
{
public readonly HttpStatusCode StatusCode = statusCode ?? HttpStatusCode.InternalServerError;
public class Unauthorized(string message) : ApiError(message, statusCode: HttpStatusCode.Unauthorized);
public class Forbidden(string message, IEnumerable<string>? scopes = null) : ApiError(message, statusCode: HttpStatusCode.Forbidden)
{
public readonly string[] Scopes = scopes?.ToArray() ?? [];
}
public class BadRequest(string message) : ApiError(message, statusCode: HttpStatusCode.BadRequest);
public class IncomingFederationError(string message) : ApiError(message, statusCode: HttpStatusCode.BadRequest);
public class OutgoingFederationError(
2024-05-20 19:42:04 +02:00
string message, Models.Http.ApiError? innerError = null
) : ApiError(message, statusCode: HttpStatusCode.InternalServerError)
{
2024-05-20 19:42:04 +02:00
public Models.Http.ApiError? InnerError => innerError;
}
public class AuthenticationError(string message) : ApiError(message, statusCode: HttpStatusCode.BadRequest);
2024-05-14 14:50:01 +02:00
}