polyte_clob/
error.rs

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