configvault_sdk/
errors.rs1use thiserror::Error;
2
3#[derive(Debug, Error)]
5pub enum ConfigVaultError {
6 #[error("configuration key '{key}' not found")]
8 NotFound { key: String },
9
10 #[error("authentication failed")]
12 Authentication,
13
14 #[error("service unavailable")]
16 ServiceUnavailable,
17
18 #[error("request failed: {0}")]
20 Request(#[from] reqwest::Error),
21
22 #[error("unexpected error: {message}")]
24 Unexpected { status: u16, message: String },
25}
26
27pub(crate) fn handle_error_response(
29 status: u16,
30 key: Option<&str>,
31) -> ConfigVaultError {
32 match status {
33 401 => ConfigVaultError::Authentication,
34 404 => ConfigVaultError::NotFound {
35 key: key.unwrap_or("unknown").to_string(),
36 },
37 503 => ConfigVaultError::ServiceUnavailable,
38 code => ConfigVaultError::Unexpected {
39 status: code,
40 message: format!("HTTP {code}"),
41 },
42 }
43}