Foxchat.NET/Foxchat.Core/FoxchatError.cs

34 lines
1.4 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;
public class FoxchatError(string message) : Exception(message)
{
public class DatabaseError(string message) : FoxchatError(message);
public class UnknownEntityError(Type entityType) : FoxchatError($"Entity of type {entityType.Name} not found");
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(
string message, Models.ApiError? innerError = null
) : ApiError(message, statusCode: HttpStatusCode.InternalServerError)
{
public Models.ApiError? InnerError => innerError;
}
public class AuthenticationError(string message) : ApiError(message, statusCode: HttpStatusCode.BadRequest);
2024-05-14 14:50:01 +02:00
}