use std::fmt;
#[derive(Debug)]
pub enum BetterStackError {
HttpError(reqwest::Error),
SerializationError(String),
ConfigError(String),
RuntimeError(String),
}
impl fmt::Display for BetterStackError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::HttpError(e) => write!(f, "HTTP error: {}", e),
Self::SerializationError(msg) => write!(f, "Serialization error: {}", msg),
Self::ConfigError(msg) => write!(f, "Configuration error: {}", msg),
Self::RuntimeError(msg) => write!(f, "Runtime error: {}", msg),
}
}
}
impl std::error::Error for BetterStackError {}
impl From<reqwest::Error> for BetterStackError {
fn from(error: reqwest::Error) -> Self {
Self::HttpError(error)
}
}
#[cfg(feature = "json")]
impl From<serde_json::Error> for BetterStackError {
fn from(error: serde_json::Error) -> Self {
Self::SerializationError(error.to_string())
}
}
#[cfg(feature = "message_pack")]
impl From<rmp_serde::encode::Error> for BetterStackError {
fn from(error: rmp_serde::encode::Error) -> Self {
Self::SerializationError(error.to_string())
}
}
#[cfg(feature = "message_pack")]
impl From<rmp_serde::decode::Error> for BetterStackError {
fn from(error: rmp_serde::decode::Error) -> Self {
Self::SerializationError(error.to_string())
}
}
pub type Result<T> = std::result::Result<T, BetterStackError>;