go_server_rust_sdk/
error.rs

1//! Error types for the go-server Rust SDK
2
3use thiserror::Error;
4
5/// Result type alias for SDK operations
6pub type Result<T> = std::result::Result<T, SdkError>;
7
8/// Main error type for the SDK
9#[derive(Error, Debug)]
10pub enum SdkError {
11    /// HTTP request errors
12    #[error("HTTP request failed: {0}")]
13    Http(#[from] reqwest::Error),
14
15    /// WebSocket connection errors
16    #[error("WebSocket error: {0}")]
17    WebSocket(Box<tokio_tungstenite::tungstenite::Error>),
18
19    /// JSON serialization/deserialization errors
20    #[error("JSON error: {0}")]
21    Json(#[from] serde_json::Error),
22
23    /// Encryption/decryption errors
24    #[error("Crypto error: {0}")]
25    Crypto(String),
26
27    /// Task execution errors
28    #[error("Task error: {0}")]
29    Task(String),
30
31    /// Connection errors
32    #[error("Connection error: {0}")]
33    Connection(String),
34
35    /// Timeout errors
36    #[error("Operation timed out")]
37    Timeout,
38
39    /// Method not found errors
40    #[error("Method '{0}' not found")]
41    MethodNotFound(String),
42
43    /// Invalid configuration errors
44    #[error("Invalid configuration: {0}")]
45    InvalidConfig(String),
46
47    /// URL parsing errors
48    #[error("URL parse error: {0}")]
49    UrlParse(#[from] url::ParseError),
50
51    /// Generic errors
52    #[error("Error: {0}")]
53    Generic(String),
54}
55
56impl From<String> for SdkError {
57    fn from(s: String) -> Self {
58        SdkError::Generic(s)
59    }
60}
61
62impl From<&str> for SdkError {
63    fn from(s: &str) -> Self {
64        SdkError::Generic(s.to_string())
65    }
66}
67
68impl From<aes_gcm::Error> for SdkError {
69    fn from(e: aes_gcm::Error) -> Self {
70        SdkError::Crypto(format!("AES-GCM error: {:?}", e))
71    }
72}
73
74impl From<base64::DecodeError> for SdkError {
75    fn from(e: base64::DecodeError) -> Self {
76        SdkError::Crypto(format!("Base64 decode error: {}", e))
77    }
78}
79
80impl From<tokio_tungstenite::tungstenite::Error> for SdkError {
81    fn from(e: tokio_tungstenite::tungstenite::Error) -> Self {
82        SdkError::WebSocket(Box::new(e))
83    }
84}