binance_api/error/mod.rs
1mod response;
2
3use reqwest::StatusCode;
4use thiserror::Error;
5
6pub use self::response::Error as ResponseError;
7
8/// Aggregated crate errors.
9#[derive(Debug, Error)]
10pub enum Error {
11 /// Binance server returned a formatted error response from API query.
12 #[error("[{http_code}] Binance error: {inner}")]
13 Server {
14 /// the actual error from a server
15 inner: ResponseError,
16 /// HTTP code associated with an error.
17 /// See more at <https://binance-docs.github.io/apidocs/spot/en/#http-return-codes>.
18 http_code: StatusCode,
19 },
20
21 /// Binance server returned not a properly formatted error response from API query.
22 #[error("[{http_code}] Plain-text Binance error: {inner}")]
23 ServerPlain {
24 /// the actual error from a server
25 inner: String,
26 /// HTTP code associated with an error.
27 /// See more at <https://binance-docs.github.io/apidocs/spot/en/#http-return-codes>.
28 http_code: StatusCode,
29 },
30
31 /// Binance server returned error code containing not a valid UTF-8 text.
32 #[error("[{0}] Unknown Binance error")]
33 ServerUnknown(
34 /// HTTP code associated with an error.
35 /// See more at <https://binance-docs.github.io/apidocs/spot/en/#http-return-codes>.
36 StatusCode,
37 ),
38
39 /// The request cannot be serialized into valid URL.
40 #[error("Serialize failure: {0}")]
41 SerializeRequest(#[from] serde_urlencoded::ser::Error),
42
43 /// The response cannot be deserialized into valid JSON.
44 #[error("Deserialize failure: {0}")]
45 DeserializeResponse(#[from] serde_json::Error),
46
47 /// General HTTP error while doing a request.
48 #[error("HTTP failure: {0}")]
49 Http(#[from] reqwest::Error),
50
51 /// The request requires an API key but it is missing.
52 #[error("Missing API key")]
53 MissingApiKey,
54
55 /// The request requires an API key but it cannot be encoded properly.
56 #[error("Invalid API key ({0})")]
57 InvalidApiKey(String),
58
59 /// The request requires secret key to sign the query but it is missing.
60 #[error("Missing secret signature key")]
61 MissingSecretKey,
62
63 /// The request requires secret key to sign the query but it is missing.
64 #[error("Invalid secret key (length={size})")]
65 InvalidSecretKey {
66 /// The size of secret key provided (the key itself hided).
67 size: usize,
68 },
69
70 /// The current timestamp (milliseconds since UNIX epoch) cannot be retrieved.
71 #[error("Cannot get timestamp")]
72 CannotGetTimestamp,
73}
74
75/// Specialised `Result` with the [global crate error][`crate::Error`].
76pub type Result<T> = std::result::Result<T, Error>;