deribit_base/error/
types.rs

1//! Common error types for Deribit clients
2
3use std::fmt;
4
5/// Common error type for all Deribit clients
6#[derive(Debug, Clone)]
7pub enum DeribitError {
8    /// Connection error
9    Connection(String),
10    /// Authentication error
11    Authentication(String),
12    /// API error with code and message
13    Api {
14        /// Error code returned by the API
15        code: i32,
16        /// Human-readable error message
17        message: String,
18    },
19    /// Serialization/deserialization error
20    Serialization(String),
21    /// Network timeout
22    Timeout,
23    /// Invalid configuration
24    InvalidConfig(String),
25    /// Generic error
26    Other(String),
27}
28
29impl fmt::Display for DeribitError {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        match self {
32            DeribitError::Connection(msg) => write!(f, "Connection error: {msg}"),
33            DeribitError::Authentication(msg) => write!(f, "Authentication error: {msg}"),
34            DeribitError::Api { code, message } => write!(f, "API error {code}: {message}"),
35            DeribitError::Serialization(msg) => write!(f, "Serialization error: {msg}"),
36            DeribitError::Timeout => write!(f, "Request timeout"),
37            DeribitError::InvalidConfig(msg) => write!(f, "Invalid configuration: {msg}"),
38            DeribitError::Other(msg) => write!(f, "Error: {msg}"),
39        }
40    }
41}
42
43impl std::error::Error for DeribitError {}
44
45/// Result type alias for Deribit operations
46pub type DeribitResult<T> = Result<T, DeribitError>;