nautilus_okx/websocket/error.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 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 thiserror::Error;
19use tokio_tungstenite::tungstenite;
20
21/// A typed error enumeration for the OKX WebSocket client.
22#[derive(Debug, Clone, Error)]
23pub enum OKXWsError {
24 #[error("Parsing error: {0}")]
25 ParsingError(String),
26 /// Errors returned directly by OKX (non-zero code).
27 #[error("OKX error {error_code}: {message}")]
28 OkxError { error_code: String, message: String },
29 /// Failure during JSON serialization/deserialization.
30 #[error("JSON error: {0}")]
31 JsonError(String),
32 #[error("Client error: {0}")]
33 ClientError(String),
34 #[error("Authentication error: {0}")]
35 AuthenticationError(String),
36 /// Wrapping the underlying HttpClientError from the network crate.
37 // #[error("Network error: {0}")]
38 // WebSocketClientError(WebSocketClientError), // TODO: Implement Debug
39 /// WebSocket transport error.
40 #[error("Tungstenite error: {0}")]
41 TungsteniteError(String),
42}
43
44impl From<tungstenite::Error> for OKXWsError {
45 fn from(error: tungstenite::Error) -> Self {
46 Self::TungsteniteError(error.to_string())
47 }
48}