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 MessageConstruction(String),
19 Session(String),
21 Io(std::io::Error),
23 Json(serde_json::Error),
25 Http(reqwest::Error),
27 Config(String),
29 Timeout(String),
31 Protocol(String),
33 Generic(String),
35}
36
37impl fmt::Display for DeribitFixError {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 match self {
40 DeribitFixError::Connection(msg) => write!(f, "Connection error: {msg}"),
41 DeribitFixError::Authentication(msg) => write!(f, "Authentication error: {msg}"),
42 DeribitFixError::MessageParsing(msg) => write!(f, "Message parsing error: {msg}"),
43 DeribitFixError::MessageConstruction(msg) => {
44 write!(f, "Message construction error: {msg}")
45 }
46 DeribitFixError::Session(msg) => write!(f, "Session error: {msg}"),
47 DeribitFixError::Io(err) => write!(f, "I/O error: {err}"),
48 DeribitFixError::Json(err) => write!(f, "JSON error: {err}"),
49 DeribitFixError::Http(err) => write!(f, "HTTP error: {err}"),
50 DeribitFixError::Config(msg) => write!(f, "Configuration error: {msg}"),
51 DeribitFixError::Timeout(msg) => write!(f, "Timeout error: {msg}"),
52 DeribitFixError::Protocol(msg) => write!(f, "Protocol error: {msg}"),
53 DeribitFixError::Generic(msg) => write!(f, "Error: {msg}"),
54 }
55 }
56}
57
58impl std::error::Error for DeribitFixError {
59 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
60 match self {
61 DeribitFixError::Io(err) => Some(err),
62 DeribitFixError::Json(err) => Some(err),
63 DeribitFixError::Http(err) => Some(err),
64 _ => None,
65 }
66 }
67}
68
69impl From<std::io::Error> for DeribitFixError {
70 fn from(err: std::io::Error) -> Self {
71 DeribitFixError::Io(err)
72 }
73}
74
75impl From<serde_json::Error> for DeribitFixError {
76 fn from(err: serde_json::Error) -> Self {
77 DeribitFixError::Json(err)
78 }
79}
80
81impl From<reqwest::Error> for DeribitFixError {
82 fn from(err: reqwest::Error) -> Self {
83 DeribitFixError::Http(err)
84 }
85}