use std::error::Error as StdError;
use std::time::Duration;
use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum AmqpError {
#[error("amqp connection error: {0}")]
Connect(#[source] Box<dyn StdError + Send + Sync>),
#[error("amqp publish error: {0}")]
Publish(#[source] Box<dyn StdError + Send + Sync>),
#[error("amqp subscribe error: {0}")]
Subscribe(#[source] Box<dyn StdError + Send + Sync>),
#[error("amqp consume error: {0}")]
Consume(#[source] Box<dyn StdError + Send + Sync>),
#[error("amqp topology declaration error: {0}")]
Declare(#[source] Box<dyn StdError + Send + Sync>),
#[error("amqp request error: {0}")]
Request(#[source] Box<dyn StdError + Send + Sync>),
#[error("amqp request timed out after {0:?} without a reply")]
RequestTimeout(Duration),
#[error("amqp broker is not connected; `Broker::connect` must complete first")]
NotConnected,
#[error("invalid options: {0}")]
InvalidOptions(String),
}
impl AmqpError {
pub(crate) fn connect(err: lapin::Error) -> Self {
Self::Connect(Box::new(err))
}
pub(crate) fn publish(err: lapin::Error) -> Self {
Self::Publish(Box::new(err))
}
pub(crate) fn subscribe(err: lapin::Error) -> Self {
Self::Subscribe(Box::new(err))
}
pub(crate) fn consume(err: lapin::Error) -> Self {
Self::Consume(Box::new(err))
}
pub(crate) fn declare(err: lapin::Error) -> Self {
Self::Declare(Box::new(err))
}
pub(crate) fn request(err: lapin::Error) -> Self {
Self::Request(Box::new(err))
}
}