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