Skip to main content

nautilus_coinbase/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
16use nautilus_network::error::SendError;
17
18/// Error type for Coinbase WebSocket operations.
19#[derive(Debug, Clone, thiserror::Error)]
20pub enum CoinbaseWsError {
21    /// URL parsing failed.
22    #[error("URL parsing failed: {0}")]
23    UrlParsing(String),
24
25    /// Message serialization failed.
26    #[error("message serialization failed: {0}")]
27    MessageSerialization(String),
28
29    /// Message deserialization failed.
30    #[error("message deserialization failed: {0}")]
31    MessageDeserialization(String),
32
33    /// WebSocket connection failed.
34    #[error("WebSocket connection failed: {0}")]
35    Connection(String),
36
37    /// Channel send failed.
38    #[error("channel send failed: {0}")]
39    ChannelSend(String),
40
41    /// Authentication failed.
42    #[error("authentication failed: {0}")]
43    Auth(String),
44
45    /// A transport send failed.
46    #[error("transport send failed: {0}")]
47    TransportSend(SendError),
48
49    /// An operation did not complete before its deadline.
50    #[error("timed out: {0}")]
51    Timeout(String),
52}
53
54impl CoinbaseWsError {
55    /// Returns true if the error is retryable (connection or channel failures).
56    #[must_use]
57    pub fn is_retryable(&self) -> bool {
58        matches!(self, Self::Connection(_) | Self::ChannelSend(_))
59    }
60}