1use polyte_core::ApiError;
2use thiserror::Error;
3
4pub type Result<T> = std::result::Result<T, ClobError>;
6
7#[derive(Error, Debug)]
9pub enum ClobError {
10 #[error(transparent)]
12 Api(#[from] ApiError),
13
14 #[error("Crypto error: {0}")]
16 Crypto(String),
17
18 #[error("Alloy error: {0}")]
20 Alloy(String),
21}
22
23impl ClobError {
24 pub(crate) async fn from_response(response: reqwest::Response) -> Self {
26 Self::Api(ApiError::from_response(response).await)
27 }
28
29 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}