bpx_api_client/
error.rs

1//! Error handling module for the Backpack Exchange API client.
2//!
3//! Defines a custom `Error` type and a `Result` type alias to encapsulate
4//! various errors that can occur during API interactions.
5
6/// A type alias for `Result` using the custom `Error` type.
7pub type Result<T> = std::result::Result<T, Error>;
8
9/// Enum representing possible errors in the Backpack Exchange API client.
10#[derive(Debug, thiserror::Error)]
11pub enum Error {
12    /// Error decoding a base64 string.
13    #[error(transparent)]
14    Base64Decode(#[from] base64::DecodeError),
15
16    /// Backpack API returned an error with status code and message.
17    #[error("Backpack API error: {status_code}: {message}")]
18    BpxApiError {
19        status_code: reqwest::StatusCode,
20        message: String,
21    },
22
23    /// Invalid HTTP header value.
24    #[error(transparent)]
25    InvalidHeaderValue(#[from] reqwest::header::InvalidHeaderValue),
26
27    /// Represents an invalid request with a custom message.
28    #[error("Invalid request: {0}")]
29    InvalidRequest(String),
30
31    /// General HTTP client error from `reqwest`.
32    #[error(transparent)]
33    Reqwest(#[from] reqwest::Error),
34
35    /// Invalid secret key provided.
36    #[error("Invalid secret key")]
37    SecretKey,
38
39    /// Error during JSON serialization or deserialization.
40    #[error(transparent)]
41    SerdeJson(#[from] serde_json::error::Error),
42
43    /// Error working with system time.
44    #[error(transparent)]
45    SystemTime(#[from] std::time::SystemTimeError),
46
47    /// UTF-8 decoding error.
48    #[error(transparent)]
49    Utf8(#[from] std::str::Utf8Error),
50
51    /// Invalid URL format.
52    #[error("Invalid URL: {0}")]
53    UrlParseError(String),
54}