use thiserror::Error;
#[derive(Debug, Error)]
pub enum ConfigVaultError {
#[error("configuration key '{key}' not found")]
NotFound { key: String },
#[error("authentication failed")]
Authentication,
#[error("service unavailable")]
ServiceUnavailable,
#[error("request failed: {0}")]
Request(#[from] reqwest::Error),
#[error("unexpected error: {message}")]
Unexpected { status: u16, message: String },
}
pub(crate) fn handle_error_response(
status: u16,
key: Option<&str>,
) -> ConfigVaultError {
match status {
401 => ConfigVaultError::Authentication,
404 => ConfigVaultError::NotFound {
key: key.unwrap_or("unknown").to_string(),
},
503 => ConfigVaultError::ServiceUnavailable,
code => ConfigVaultError::Unexpected {
status: code,
message: format!("HTTP {code}"),
},
}
}