Hydra/Hydra.Backend/HydraError.cs

29 lines
1.1 KiB
C#
Raw Normal View History

2024-08-04 15:57:10 +02:00
using System.Net;
namespace Hydra.Backend;
public class HydraError(string message, Exception? inner = null) : Exception(message)
{
public Exception? Inner => inner;
public class DatabaseError(string message, Exception? inner = null) : HydraError(message, inner);
public class UnknownEntityError(Type entityType, Exception? inner = null)
: DatabaseError($"Entity of type {entityType.Name} not found", inner);
}
public class ApiError(string message, HttpStatusCode? statusCode = null)
: HydraError(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 AuthenticationError(string message) : ApiError(message, statusCode: HttpStatusCode.BadRequest);
}