use std::fmt; pub use export::is_unique_violation; #[derive(Debug)] pub enum SpaceError { BadRequest(String), Unauthorized, Forbidden, NotFound, Conflict(String), RateLimited(String), Internal(String), } impl fmt::Display for SpaceError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::BadRequest(message) => write!(f, "{message}"), Self::Unauthorized => write!(f, "unauthorized"), Self::Forbidden => write!(f, "forbidden"), Self::NotFound => write!(f, "not found"), Self::Conflict(message) => write!(f, "{message}"), Self::RateLimited(message) => write!(f, "{message}"), Self::Internal(message) => write!(f, "{message}"), } } } impl std::error::Error for SpaceError {} export::db_error_conversions!(SpaceError); export::storage_error_conversion!(SpaceError); export::export_error_conversion!(SpaceError); export::json_payload_conversion!(SpaceError); export::api_error! { log: "space", pub enum ApiError { BadRequest(400, "request failed validation"), Unauthorized(401, "authentication required"), Forbidden(403, "operation not allowed"), NotFound(404, "resource not found"), Conflict(409, "resource conflict"), TooManyRequests(429, "rate limit exceeded"), Internal(500, "internal server error"), } } impl From for ApiError { fn from(error: SpaceError) -> Self { match error { SpaceError::BadRequest(msg) => Self::bad_request(msg), SpaceError::Unauthorized => Self::unauthorized(), SpaceError::Forbidden => Self::forbidden(), SpaceError::NotFound => Self::not_found("space resource not found"), SpaceError::Conflict(msg) => Self::conflict(msg), SpaceError::RateLimited(msg) => Self::rate_limited(msg), SpaceError::Internal(message) => Self::internal(message), } } }