polyte_clob/
error.rs

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