nautilus_coinbase_intx/http/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//! Defines the error structures and enumerations for the Coinbase International integration.
17//!
18//! This module includes data types for deserializing exchange errors from Coinbase International
19//! (`CoinbaseIntxErrorResponse`, `CoinbaseIntxErrorMessage`), as well as a higher-level typed
20//! error enum (`CoinbaseIntxHttpError`) that represents the various failure states in
21//! the client (e.g., missing credentials, network errors, unexpected status
22//! codes, etc.).
23
24use nautilus_network::http::{HttpClientError, StatusCode};
25use serde::Deserialize;
26use thiserror::Error;
27
28/// Represents the JSON structure of an error response returned by the Coinbase API.
29#[derive(Clone, Debug, Deserialize)]
30pub struct CoinbaseIntxErrorResponse {
31 /// The top-level error object included in the Coinbase error response.
32 pub error: CoinbaseIntxErrorMessage,
33}
34
35/// Contains the specific error details provided by the Coinbase API.
36#[derive(Clone, Debug, Deserialize)]
37pub struct CoinbaseIntxErrorMessage {
38 /// A human-readable explanation of the error condition.
39 pub message: String,
40 /// A short identifier or category for the error, as returned by Coinbase.
41 pub name: String,
42}
43
44#[derive(Deserialize)]
45pub(crate) struct ErrorBody {
46 pub title: Option<String>,
47 pub error: Option<String>,
48}
49
50/// A typed error enumeration for the Coinbase HTTP client.
51#[derive(Debug, Error)]
52pub enum CoinbaseIntxHttpError {
53 /// Error variant when credentials are missing but the request is authenticated.
54 #[error("Missing credentials for authenticated request")]
55 MissingCredentials,
56 /// Errors returned directly by Coinbase (non-zero code).
57 #[error("{error_code}: {message}")]
58 CoinbaseError { error_code: String, message: String },
59 /// Failure during URL parameter encoding or JSON serialization/deserialization.
60 /// Covers errors from `serde_urlencoded` and `serde_json`.
61 #[error("Serialization error: {0}")]
62 JsonError(String),
63 /// Underlying network or HTTP client error.
64 #[error("Network error: {0}")]
65 HttpClientError(#[from] HttpClientError),
66 /// Any unknown HTTP status or unexpected response from Coinbase.
67 #[error("Unexpected HTTP status code {status}: {body}")]
68 UnexpectedStatus { status: StatusCode, body: String },
69}