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: Box<str>,
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(Box<str>),
30
31 /// Client needs to be authenticated to perform the requested action.
32 #[error("Client is not authenticated")]
33 NotAuthenticated,
34
35 /// General HTTP client error from `reqwest`.
36 #[error(transparent)]
37 Reqwest(#[from] reqwest::Error),
38
39 /// Invalid secret key provided.
40 #[error("Invalid secret key")]
41 SecretKey,
42
43 /// Error during JSON serialization or deserialization.
44 #[error(transparent)]
45 SerdeJson(#[from] serde_json::error::Error),
46
47 /// Error working with system time.
48 #[error(transparent)]
49 SystemTime(#[from] std::time::SystemTimeError),
50
51 /// UTF-8 decoding error.
52 #[error(transparent)]
53 Utf8(#[from] std::str::Utf8Error),
54
55 /// Invalid URL format.
56 #[error("Invalid URL: {0}")]
57 UrlParseError(Box<str>),
58}