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)
|
|
|
|
{
|
2024-05-19 23:51:53 +02:00
|
|
|
public class BadRequest(string message) : ApiError(message, statusCode: HttpStatusCode.BadRequest);
|
|
|
|
public class IncomingFederationError(string message) : ApiError(message, statusCode: HttpStatusCode.BadRequest);
|
2024-05-14 14:50:01 +02:00
|
|
|
|
2024-05-19 23:51:53 +02:00
|
|
|
public class OutgoingFederationError(
|
|
|
|
string message, Models.ApiError? innerError = null
|
|
|
|
) : ApiError(message, statusCode: HttpStatusCode.InternalServerError)
|
2024-05-14 14:50:01 +02:00
|
|
|
{
|
|
|
|
public Models.ApiError? InnerError => innerError;
|
|
|
|
}
|
|
|
|
|
|
|
|
public class DatabaseError(string message) : FoxchatError(message);
|
2024-05-19 23:51:53 +02:00
|
|
|
public class AuthenticationError(string message) : ApiError(message, statusCode: HttpStatusCode.BadRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
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() ?? [];
|
|
|
|
}
|
2024-05-14 14:50:01 +02:00
|
|
|
}
|