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;
25use reqwest::StatusCode;
26use serde::Deserialize;
27use thiserror::Error;
28
29/// Represents the JSON structure of an error response returned by the Coinbase API.
30#[derive(Clone, Debug, Deserialize)]
31pub struct CoinbaseIntxErrorResponse {
32    /// The top-level error object included in the Coinbase error response.
33    pub error: CoinbaseIntxErrorMessage,
34}
35
36/// Contains the specific error details provided by the Coinbase API.
37#[derive(Clone, Debug, Deserialize)]
38pub struct CoinbaseIntxErrorMessage {
39    /// A human-readable explanation of the error condition.
40    pub message: String,
41    /// A short identifier or category for the error, as returned by Coinbase.
42    pub name: String,
43}
44
45#[derive(Deserialize)]
46pub(crate) struct ErrorBody {
47    pub title: Option<String>,
48    pub error: Option<String>,
49}
50
51/// A typed error enumeration for the Coinbase HTTP client.
52#[derive(Debug, Error)]
53pub enum CoinbaseIntxHttpError {
54    /// Error variant when credentials are missing but the request is authenticated.
55    #[error("Missing credentials for authenticated request")]
56    MissingCredentials,
57    /// Errors returned directly by Coinbase (non-zero code).
58    #[error("{error_code}: {message}")]
59    CoinbaseError { error_code: String, message: String },
60    /// Failure during JSON serialization/deserialization.
61    #[error("JSON error: {0}")]
62    JsonError(String),
63    /// Wrapping the underlying HttpClientError from the network crate.
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}