use thiserror::Error;
#[derive(Debug, Error)]
pub enum ProviderError {
#[error("authentication failed for provider '{provider}': {message}")]
AuthError {
provider: &'static str,
message: String,
},
#[error("bad request to provider '{provider}': {message}")]
BadRequest {
provider: &'static str,
message: String,
},
#[error("rate limited by provider '{provider}'")]
RateLimited { provider: &'static str },
#[error("provider '{provider}' unavailable: {message}")]
Unavailable {
provider: &'static str,
message: String,
},
#[error("provider '{provider}' returned unparseable response: {message}")]
ParseError {
provider: &'static str,
message: String,
},
#[error("no API key configured for provider '{provider}'; set {env_var}")]
MissingApiKey {
provider: &'static str,
env_var: &'static str,
},
#[error("provider error: {0}")]
Other(#[from] anyhow::Error),
}
impl ProviderError {
pub fn is_retryable(&self) -> bool {
matches!(self, Self::RateLimited { .. } | Self::Unavailable { .. })
}
}