use thiserror::Error;
#[derive(Debug, Error)]
pub enum GatewayError {
#[error("Configuration error: {0}")]
Config(String),
#[error("Failed to load schema: {0}")]
Schema(String),
#[error("Failed to load policy: {0}")]
Policy(String),
#[error("Database error: {0}")]
Database(String),
#[error("Authentication failed: {0}")]
Auth(String),
#[error("Access denied: {0}")]
AccessDenied(String),
#[error("Invalid query: {0}")]
InvalidQuery(String),
#[error("Internal error: {0}")]
Internal(#[from] anyhow::Error),
}
impl GatewayError {
pub fn status_code(&self) -> u16 {
match self {
Self::Config(_) => 500,
Self::Schema(_) => 500,
Self::Policy(_) => 500,
Self::Database(_) => 503,
Self::Auth(_) => 401,
Self::AccessDenied(_) => 403,
Self::InvalidQuery(_) => 400,
Self::Internal(_) => 500,
}
}
}