Skip to main content

vyper_client_rs/
errors.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum VyperError {
5    #[error("HTTP error: {0}")]
6    HttpError(#[from] reqwest::Error),
7
8    #[error("Deserialization error: {0}")]
9    DeserializeError(#[from] serde_json::Error),
10
11    #[error("Authentication error: {0}")]
12    AuthenticationError(String),
13
14    #[error("Rate limit error: {message}")]
15    RateLimitError {
16        message: String,
17        retry_after: Option<f64>,
18    },
19
20    #[error("Server error: {0}")]
21    ServerError(String),
22
23    #[error("API error: {0} (Status: {1})")]
24    ApiError(String, u16),
25
26    #[error("Websocket error: {message}")]
27    WebsocketError {
28        message: String,
29        status_code: Option<u16>,
30        connection_info: Option<String>,
31    },
32}
33
34impl VyperError {
35    pub fn websocket_error<S: Into<String>>(message: S, status_code: Option<u16>, connection_info: Option<String>) -> Self {
36        VyperError::WebsocketError {
37            message: message.into(),
38            status_code,
39            connection_info,
40        }
41    }
42}
43
44impl From<&str> for VyperError {
45    fn from(s: &str) -> Self {
46        VyperError::WebsocketError {
47            message: s.to_string(),
48            status_code: None,
49            connection_info: None,
50        }
51    }
52}