use std::error::Error as StdError;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SqsError {
#[error("aws config error: {0}")]
Config(String),
#[error("sqs queue error for '{name}': {source}")]
Queue {
name: String,
#[source]
source: Box<dyn StdError + Send + Sync>,
},
#[error("sqs receive error on '{queue}': {source}")]
Receive {
queue: String,
#[source]
source: Box<dyn StdError + Send + Sync>,
},
#[error("publish error to '{destination}': {source}")]
Publish {
destination: String,
#[source]
source: Box<dyn StdError + Send + Sync>,
},
#[error("sns admin error for '{name}': {source}")]
Admin {
name: String,
#[source]
source: Box<dyn StdError + Send + Sync>,
},
#[error("sqs broker is not connected")]
NotConnected,
#[error("invalid sqs queue descriptor: {0}")]
InvalidQueue(String),
}
pub(crate) fn sdk_err<E, R>(
err: &aws_sdk_sqs::error::SdkError<E, R>,
) -> Box<dyn StdError + Send + Sync>
where
E: StdError + Send + Sync + 'static,
R: std::fmt::Debug + Send + Sync + 'static,
{
Box::from(aws_sdk_sqs::error::DisplayErrorContext(err).to_string())
}