tracing_better_stack/
error.rs1use std::fmt;
2
3#[derive(Debug)]
8pub enum BetterStackError {
9 HttpError(reqwest::Error),
13
14 SerializationError(String),
18
19 ConfigError(String),
23
24 RuntimeError(String),
28}
29
30impl fmt::Display for BetterStackError {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 match self {
33 Self::HttpError(e) => write!(f, "HTTP error: {}", e),
34 Self::SerializationError(msg) => write!(f, "Serialization error: {}", msg),
35 Self::ConfigError(msg) => write!(f, "Configuration error: {}", msg),
36 Self::RuntimeError(msg) => write!(f, "Runtime error: {}", msg),
37 }
38 }
39}
40
41impl std::error::Error for BetterStackError {}
42
43impl From<reqwest::Error> for BetterStackError {
44 fn from(error: reqwest::Error) -> Self {
45 Self::HttpError(error)
46 }
47}
48
49#[cfg(feature = "json")]
50impl From<serde_json::Error> for BetterStackError {
51 fn from(error: serde_json::Error) -> Self {
52 Self::SerializationError(error.to_string())
53 }
54}
55
56#[cfg(feature = "message_pack")]
57impl From<rmp_serde::encode::Error> for BetterStackError {
58 fn from(error: rmp_serde::encode::Error) -> Self {
59 Self::SerializationError(error.to_string())
60 }
61}
62
63#[cfg(feature = "message_pack")]
64impl From<rmp_serde::decode::Error> for BetterStackError {
65 fn from(error: rmp_serde::decode::Error) -> Self {
66 Self::SerializationError(error.to_string())
67 }
68}
69
70pub type Result<T> = std::result::Result<T, BetterStackError>;