1use std::fmt;
4
5pub type Result<T> = std::result::Result<T, DeribitFixError>;
7
8#[derive(Debug)]
10pub enum DeribitFixError {
11 Connection(String),
13 Authentication(String),
15 MessageParsing(String),
17 Session(String),
19 Io(std::io::Error),
21 Json(serde_json::Error),
23 Http(reqwest::Error),
25 Config(String),
27 Timeout(String),
29 Protocol(String),
31 Generic(String),
33}
34
35impl fmt::Display for DeribitFixError {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 match self {
38 DeribitFixError::Connection(msg) => write!(f, "Connection error: {}", msg),
39 DeribitFixError::Authentication(msg) => write!(f, "Authentication error: {}", msg),
40 DeribitFixError::MessageParsing(msg) => write!(f, "Message parsing error: {}", msg),
41 DeribitFixError::Session(msg) => write!(f, "Session error: {}", msg),
42 DeribitFixError::Io(err) => write!(f, "I/O error: {}", err),
43 DeribitFixError::Json(err) => write!(f, "JSON error: {}", err),
44 DeribitFixError::Http(err) => write!(f, "HTTP error: {}", err),
45 DeribitFixError::Config(msg) => write!(f, "Configuration error: {}", msg),
46 DeribitFixError::Timeout(msg) => write!(f, "Timeout error: {}", msg),
47 DeribitFixError::Protocol(msg) => write!(f, "Protocol error: {}", msg),
48 DeribitFixError::Generic(msg) => write!(f, "Error: {}", msg),
49 }
50 }
51}
52
53impl std::error::Error for DeribitFixError {
54 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
55 match self {
56 DeribitFixError::Io(err) => Some(err),
57 DeribitFixError::Json(err) => Some(err),
58 DeribitFixError::Http(err) => Some(err),
59 _ => None,
60 }
61 }
62}
63
64impl From<std::io::Error> for DeribitFixError {
65 fn from(err: std::io::Error) -> Self {
66 DeribitFixError::Io(err)
67 }
68}
69
70impl From<serde_json::Error> for DeribitFixError {
71 fn from(err: serde_json::Error) -> Self {
72 DeribitFixError::Json(err)
73 }
74}
75
76impl From<reqwest::Error> for DeribitFixError {
77 fn from(err: reqwest::Error) -> Self {
78 DeribitFixError::Http(err)
79 }
80}