bothan_htx/api/
error.rs

1//! Error types for HTX API client operations.
2//!
3//! This module provides custom error types used throughout the HTX API integration,
4//! particularly for handling websocket messages, data parsing, and connection management.
5
6use std::io;
7
8use tokio_tungstenite::tungstenite;
9
10/// Errors related to HTX API client operations.
11///
12/// These errors can occur during communication with the HTX WebSocket API,
13/// including message parsing, I/O operations, and unsupported message types.
14#[derive(Debug, thiserror::Error)]
15pub enum Error {
16    /// Indicates a failure to read WebSocket messages.
17    #[error("failed to read message")]
18    Io(#[from] io::Error),
19
20    /// Indicates a failure to parse a WebSocket message.
21    #[error("failed to parse message")]
22    ParseError(#[from] serde_json::Error),
23
24    /// Indicates that the WebSocket message type is not supported.
25    #[error("unsupported message")]
26    UnsupportedWebsocketMessageType,
27}
28
29/// Errors encountered while listening for HTX API events.
30///
31/// These errors can occur during subscription to asset updates, message processing,
32/// or when handling ping/pong messages from the HTX WebSocket stream.
33#[derive(Debug, thiserror::Error)]
34pub enum ListeningError {
35    /// Indicates an error while processing WebSocket messages.
36    #[error(transparent)]
37    Error(#[from] Error),
38
39    /// Indicates that the received channel ID is invalid or malformed.
40    #[error("received invalid channel id")]
41    InvalidChannelId,
42
43    /// Indicates that the received price data contains NaN values.
44    #[error("received NaN")]
45    InvalidPrice,
46
47    /// Indicates a failure to send a pong response to a ping message.
48    #[error("failed to pong")]
49    PongFailed(#[from] tungstenite::Error),
50}