coinbase_v3/
error.rs

1//! Error type for the client and matching Coinbase's API responses
2use reqwest;
3use serde_derive::{Deserialize, Serialize};
4use std::fmt;
5use thiserror::Error;
6
7/// Structure to deserialize the details of Coinbase's API error responses
8#[derive(Serialize, Deserialize, Debug)]
9struct CbRequestErrorDetails {
10    type_url: String,
11    value: u8,
12}
13
14/// Structure to deserialize Coinbase's API error responses
15#[derive(thiserror::Error, Serialize, Deserialize, Debug)]
16pub struct CbRequestError {
17    error: String,
18    code: i32,
19    message: String,
20    details: CbRequestErrorDetails,
21}
22
23impl fmt::Display for CbRequestError {
24    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25        write!(f, "{:#?}", self)
26    }
27}
28
29/// Enum accounting for the different error types arising from the client
30#[derive(Debug, Error)]
31pub enum CbError {
32    #[error("http error {0}")]
33    Http(#[from] reqwest::Error),
34    #[error(transparent)]
35    Serde(#[from] serde_json::Error),
36    #[error("Coinbase: {0}")]
37    Coinbase(CbRequestError),
38}