Skip to main content

rust_okx/ws/
error.rs

1//! WebSocket-layer error type.
2
3use crate::transport::TransportError;
4
5/// Errors from the WebSocket layer.
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum WsError {
9    /// A WebSocket transport error (connection, TLS, I/O, …).
10    #[error("WebSocket transport error: {source}")]
11    Transport {
12        /// Finding the position of the error
13        #[from]
14        source: TransportError,
15    },
16
17    /// A WebSocket event or push payload could not be decoded.
18    #[error("failed to decode WebSocket message ({context})")]
19    Decode {
20        /// Human-readable context: channel name, event type, or a snippet of
21        /// the raw payload.
22        context: String,
23        /// The underlying deserialization error.
24        #[source]
25        source: serde_json::Error,
26    },
27
28    /// A push event was missing the required `arg` field.
29    #[error("missing `arg` field in WebSocket event: {raw}")]
30    MissingArg {
31        /// The raw JSON text of the offending event (truncated if large).
32        raw: String,
33    },
34
35    /// An outgoing WebSocket request could not be serialized.
36    #[error("failed to encode WebSocket request")]
37    Encode {
38        /// The underlying serialization error.
39        #[source]
40        source: serde_json::Error,
41    },
42
43    /// The WebSocket client was used in an invalid way (wrong channel group,
44    /// missing credentials, …).
45    #[error("invalid configuration: {0}")]
46    Configuration(String),
47}