ds_common_aws_rs_lib/sqs/
error.rs

1//! AWS SQS error module.
2//!
3//! This module contains error types specific to AWS SQS operations.
4
5use thiserror::Error;
6
7// region: --> SqsError
8
9/// Errors that can occur during AWS SQS operations.
10///
11/// This enum covers all possible errors when creating SQS clients or processing messages,
12/// including SQS client or operation errors, and not found errors.
13#[derive(Error, Debug)]
14pub enum SqsError {
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: --> SqsError
41
42// region: --> Helpers
43
44/// Convert AWS SDK errors to SqsError
45pub fn map_sqs_err<E, R>(e: aws_smithy_runtime_api::client::result::SdkError<E, R>) -> SqsError
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) => SqsError::Build,
52        TimeoutError(_te) => SqsError::Timeout { request_id: None },
53        DispatchFailure(_df) => SqsError::Transport {
54            request_id: None,
55            source: Box::new(std::io::Error::other("Dispatch failure")),
56        },
57        ResponseError(_re) => SqsError::Service(Box::new(std::io::Error::other("Response error"))),
58        ServiceError(se) => SqsError::Service(Box::new(se.into_err())),
59        _ => SqsError::Service(Box::new(std::io::Error::other("Unknown error"))),
60    }
61}
62
63// endregion: --> Helpers