Skip to main content

stygian_proxy/
error.rs

1/// Proxy error types and result alias.
2use thiserror::Error;
3
4/// Errors that can occur within the stygian-proxy library.
5///
6/// # Examples
7///
8/// ```rust
9/// use stygian_proxy::error::{ProxyError, ProxyResult};
10///
11/// fn example() -> ProxyResult<()> {
12///     Err(ProxyError::PoolExhausted)
13/// }
14/// ```
15#[derive(Debug, Error)]
16pub enum ProxyError {
17    /// The proxy pool has no available proxies to hand out.
18    #[error("proxy pool is exhausted")]
19    PoolExhausted,
20
21    /// Every proxy in the pool is currently unhealthy or has an open circuit.
22    #[error("all proxies are unhealthy")]
23    AllProxiesUnhealthy,
24
25    /// A supplied proxy URL failed validation.
26    #[error("invalid proxy URL `{url}`: {reason}")]
27    InvalidProxyUrl {
28        /// The URL that was rejected.
29        url: String,
30        /// Human-readable explanation of the validation failure.
31        reason: String,
32    },
33
34    /// A health check request for a proxy failed.
35    #[error("health check failed for proxy `{proxy}`: {message}")]
36    HealthCheckFailed {
37        /// Display form of the proxy URL (credentials redacted).
38        proxy: String,
39        /// Description of the underlying error.
40        message: String,
41    },
42
43    /// The circuit breaker for this proxy is open — calls are being rejected fast.
44    #[error("circuit breaker is open for proxy `{proxy}`")]
45    CircuitOpen {
46        /// Display form of the proxy URL (credentials redacted).
47        proxy: String,
48    },
49
50    /// An error from the underlying storage layer.
51    #[error("storage error: {0}")]
52    StorageError(String),
53
54    /// A configuration error.
55    #[error("configuration error: {0}")]
56    ConfigError(String),
57}
58
59/// Convenience result alias for all stygian-proxy operations.
60pub type ProxyResult<T> = Result<T, ProxyError>;