use std::fmt::{Formatter, Display};
#[derive(Debug)]
pub enum MessageQueueError {
NonExistentTopic(String),
FailedToPublish(String),
ClientConnectionError(String),
ConfigConstructionError(String),
SubscriptionConnectionError(String),
DecodeError(String),
SubscriptionNotConfiguredError(String),
}
impl Display for MessageQueueError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
MessageQueueError::NonExistentTopic(topic) => {
write!(f, "The topic {} does not exist", topic)
}
MessageQueueError::FailedToPublish(e) => {
write!(f, "Failed to publish message: {}", e)
}
MessageQueueError::ClientConnectionError(e) => {
write!(
f,
"Failed to connect to the message queue's underlying client: {}",
e
)
}
MessageQueueError::ConfigConstructionError(e) => {
write!(
f,
"Failed to construct the message queue's underlying client: {}",
e
)
}
MessageQueueError::SubscriptionConnectionError(e) => {
write!(f, "Failed to connect to the subscription: {}", e)
}
MessageQueueError::DecodeError(e) => {
write!(f, "Failed to decode the message data: {}", e)
}
MessageQueueError::SubscriptionNotConfiguredError(e) => {
write!(f, "Subscription not configured: {}", e)
}
}
}
}