use std::{fmt::Display, error::Error as StdError};
#[cfg(feature = "topic")]
use crate::RoutingKeyError;
#[derive(Debug)]
pub enum Error {
Mq(lapin::Error),
Serde(Box<dyn StdError + Send + Sync>),
Uuid(uuid::Error),
#[cfg(feature = "rpc")]
Reply(crate::ReplyError),
#[cfg(feature = "topic")]
RoutingKey(RoutingKeyError),
}
impl From<lapin::Error> for Error {
fn from(e: lapin::Error) -> Self {
Self::Mq(e)
}
}
impl From<uuid::Error> for Error {
fn from(e: uuid::Error) -> Self {
Self::Uuid(e)
}
}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Mq(e) => write!(f, "Rabbit MQ error: {e}"),
Error::Serde(e) => write!(f, "(De)serialization error {e}"),
Error::Uuid(e) => write!(f, "UUID error: {e}"),
#[cfg(feature = "rpc")]
Error::Reply(e) => write!(f, "Reply error: {e}"),
#[cfg(feature = "topic")]
Error::RoutingKey(e) => write!(f, "Error creating routing key: {e}"),
}
}
}
impl std::error::Error for Error {}