Skip to main content

xrpl_mithril_client/
error.rs

1//! Error types for the XRPL client.
2
3use std::time::Duration;
4
5/// Errors that can occur when communicating with an XRPL node.
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum ClientError {
9    /// JSON-RPC error response from the server.
10    #[error("RPC error: {message}")]
11    RpcError {
12        /// Numeric error code from the server, if present.
13        code: Option<i32>,
14        /// Human-readable error message.
15        message: String,
16        /// Machine-readable error name (e.g., `"actNotFound"`).
17        error: Option<String>,
18    },
19
20    /// HTTP transport error (connection refused, timeout, TLS, etc.).
21    #[error("HTTP error: {0}")]
22    Http(#[from] reqwest::Error),
23
24    /// WebSocket transport error.
25    #[error("WebSocket error: {0}")]
26    WebSocket(String),
27
28    /// WebSocket connection closed unexpectedly.
29    #[error("WebSocket connection closed: {reason}")]
30    ConnectionClosed {
31        /// The reason the connection was closed.
32        reason: String,
33    },
34
35    /// JSON serialization or deserialization error.
36    #[error("JSON error: {0}")]
37    Json(#[from] serde_json::Error),
38
39    /// The server response was missing expected fields.
40    #[error("unexpected response format: {0}")]
41    UnexpectedResponse(String),
42
43    /// Request timed out.
44    #[error("request timed out after {0:?}")]
45    Timeout(Duration),
46
47    /// Invalid URL provided.
48    #[error("invalid URL: {0}")]
49    InvalidUrl(String),
50
51    /// A subscription stream ended unexpectedly.
52    #[error("subscription stream ended")]
53    SubscriptionEnded,
54}