nautilus_okx/websocket/error.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Error types produced by the OKX WebSocket client implementation.
17
18use nautilus_network::error::SendError;
19use thiserror::Error;
20use tokio_tungstenite::tungstenite;
21
22/// A typed error enumeration for the OKX WebSocket client.
23#[derive(Debug, Clone, Error)]
24pub enum OKXWsError {
25 #[error("Parsing error: {0}")]
26 ParsingError(String),
27 /// Errors returned directly by OKX (non-zero code).
28 #[error("OKX error {error_code}: {message}")]
29 OkxError { error_code: String, message: String },
30 /// Failure during JSON serialization/deserialization.
31 #[error("JSON error: {0}")]
32 JsonError(String),
33 #[error("Client error: {0}")]
34 ClientError(String),
35 #[error("No active WebSocket client")]
36 NoActiveClient,
37 #[error("Handler not available: {0}")]
38 HandlerUnavailable(String),
39 /// A typed failure from the shared WebSocket send boundary.
40 #[error("WebSocket send error: {0}")]
41 TransportSend(#[from] SendError),
42 /// A send failure whose delivery outcome is unknown.
43 #[error("Send failed: {0}")]
44 SendFailed(String),
45 #[error("Operation timed out after {timeout_ms}ms")]
46 OperationTimeout { timeout_ms: u64 },
47 #[error("Authentication error: {0}")]
48 AuthenticationError(String),
49 /// Wrapping the underlying `HttpClientError` from the network crate.
50 // #[error("Network error: {0}")]
51 // WebSocketClientError(WebSocketClientError), // TODO: Implement Debug
52 /// WebSocket transport error.
53 #[error("Tungstenite error: {0}")]
54 TungsteniteError(String),
55}
56
57impl From<tungstenite::Error> for OKXWsError {
58 fn from(error: tungstenite::Error) -> Self {
59 Self::TungsteniteError(error.to_string())
60 }
61}
62
63impl From<String> for OKXWsError {
64 fn from(msg: String) -> Self {
65 Self::AuthenticationError(msg)
66 }
67}