Skip to main content

polyoxide_clob/
error.rs

1use polyoxide_core::ApiError;
2use thiserror::Error;
3
4use crate::types::ParseTickSizeError;
5
6/// Error types for CLOB API operations
7#[derive(Error, Debug)]
8pub enum ClobError {
9    /// Core API error
10    #[error(transparent)]
11    Api(#[from] ApiError),
12
13    /// Cryptographic operation failed
14    #[error("Crypto error: {0}")]
15    Crypto(String),
16
17    /// Alloy (Ethereum library) error
18    #[error("Alloy error: {0}")]
19    Alloy(String),
20
21    /// Invalid tick size
22    #[error(transparent)]
23    InvalidTickSize(#[from] ParseTickSizeError),
24}
25
26impl ClobError {
27    /// Create error from HTTP response
28    pub(crate) async fn from_response(response: reqwest::Response) -> Self {
29        Self::Api(ApiError::from_response(response).await)
30    }
31
32    /// Create validation error
33    pub(crate) fn validation(msg: impl Into<String>) -> Self {
34        Self::Api(ApiError::Validation(msg.into()))
35    }
36
37    /// Create service error
38    pub(crate) fn service(msg: impl Into<String>) -> Self {
39        Self::Api(ApiError::Validation(msg.into()))
40    }
41}
42
43impl From<alloy::signers::Error> for ClobError {
44    fn from(err: alloy::signers::Error) -> Self {
45        Self::Alloy(err.to_string())
46    }
47}
48
49impl From<alloy::hex::FromHexError> for ClobError {
50    fn from(err: alloy::hex::FromHexError) -> Self {
51        Self::Alloy(err.to_string())
52    }
53}
54
55impl From<reqwest::Error> for ClobError {
56    fn from(err: reqwest::Error) -> Self {
57        Self::Api(ApiError::Network(err))
58    }
59}
60
61impl From<url::ParseError> for ClobError {
62    fn from(err: url::ParseError) -> Self {
63        Self::Api(ApiError::Url(err))
64    }
65}
66
67impl From<serde_json::Error> for ClobError {
68    fn from(err: serde_json::Error) -> Self {
69        Self::Api(ApiError::Serialization(err))
70    }
71}