use thiserror::Error;
#[derive(Debug, Error)]
pub enum MessengerError {
#[error("config error: {0}")]
Config(String),
#[error("auth error: {0}")]
Auth(String),
#[error("state error: {0}")]
State(String),
#[error("network error")]
Network(#[from] reqwest::Error),
#[error("mqtt client error")]
MqttClient(#[from] rumqttc::ClientError),
#[error("mqtt connection error")]
MqttConnection(Box<rumqttc::ConnectionError>),
#[error("serialization error")]
Json(#[from] serde_json::Error),
#[error("io error")]
Io(#[from] std::io::Error),
#[error("regex error")]
Regex(#[from] regex::Error),
#[error("request timed out")]
Timeout,
#[error("protocol error: {0}")]
Protocol(String),
#[error("client is not started")]
NotStarted,
}
impl From<rumqttc::ConnectionError> for MessengerError {
fn from(error: rumqttc::ConnectionError) -> Self {
Self::MqttConnection(Box::new(error))
}
}