ds_common_aws_rs_lib/ssm/
error.rs

1//! AWS SSM error module.
2//!
3//! This module contains error types specific to AWS SSM operations.
4
5use thiserror::Error;
6
7// region: --> SsmError
8
9/// Errors that can occur during AWS SSM operations.
10///
11/// This enum covers all possible errors when creating SSM clients or processing parameters,
12/// including SSM client or operation errors, and not found errors.
13#[derive(Error, Debug)]
14pub enum SsmError {
15    /// Request build failed
16    #[error("request build failed")]
17    Build,
18
19    /// Network/dispatch failure
20    #[error("network/dispatch failed")]
21    Transport {
22        #[source]
23        source: Box<dyn std::error::Error + Send + Sync>,
24        request_id: Option<String>,
25    },
26
27    /// Request timeout
28    #[error("timeout")]
29    Timeout { request_id: Option<String> },
30
31    /// Service error
32    #[error("service error: {0}")]
33    Service(#[source] Box<dyn std::error::Error + Send + Sync>),
34
35    /// Invalid response
36    #[error("Invalid response: {0}")]
37    InvalidResponse(String),
38}
39
40// endregion: --> SsmError
41
42// region: --> Helpers
43
44/// Convert AWS SDK errors to SsmError
45pub fn map_ssm_err<E, R>(e: aws_smithy_runtime_api::client::result::SdkError<E, R>) -> SsmError
46where
47    E: std::error::Error + Send + Sync + 'static,
48{
49    use aws_smithy_runtime_api::client::result::SdkError::*;
50    match e {
51        ConstructionFailure(_cf) => SsmError::Build,
52        TimeoutError(_te) => SsmError::Timeout { request_id: None },
53        DispatchFailure(_df) => SsmError::Transport {
54            request_id: None,
55            source: Box::new(std::io::Error::other("Dispatch failure")),
56        },
57        ResponseError(_re) => SsmError::Service(Box::new(std::io::Error::other("Response error"))),
58        ServiceError(se) => SsmError::Service(Box::new(se.into_err())),
59        _ => SsmError::Service(Box::new(std::io::Error::other("Unknown error"))),
60    }
61}
62
63// endregion: --> Helpers