qail_gateway/
error.rs

1//! Gateway error types
2
3use thiserror::Error;
4
5/// Main error type for the gateway
6#[derive(Debug, Error)]
7pub enum GatewayError {
8    /// Configuration error
9    #[error("Configuration error: {0}")]
10    Config(String),
11    
12    /// Schema loading error
13    #[error("Failed to load schema: {0}")]
14    Schema(String),
15    
16    /// Policy loading error
17    #[error("Failed to load policy: {0}")]
18    Policy(String),
19    
20    /// Database connection error
21    #[error("Database error: {0}")]
22    Database(String),
23    
24    /// Authentication error
25    #[error("Authentication failed: {0}")]
26    Auth(String),
27    
28    /// Authorization error (policy violation)
29    #[error("Access denied: {0}")]
30    AccessDenied(String),
31    
32    /// Query validation error
33    #[error("Invalid query: {0}")]
34    InvalidQuery(String),
35    
36    /// Internal server error
37    #[error("Internal error: {0}")]
38    Internal(#[from] anyhow::Error),
39}
40
41impl GatewayError {
42    /// Get HTTP status code for this error
43    pub fn status_code(&self) -> u16 {
44        match self {
45            Self::Config(_) => 500,
46            Self::Schema(_) => 500,
47            Self::Policy(_) => 500,
48            Self::Database(_) => 503,
49            Self::Auth(_) => 401,
50            Self::AccessDenied(_) => 403,
51            Self::InvalidQuery(_) => 400,
52            Self::Internal(_) => 500,
53        }
54    }
55}