Skip to main content

gateio_rs/http/
error.rs

1use serde::Deserialize;
2use std::collections::HashMap;
3
4/// Unsuccessful response from the Gate API.
5#[derive(Debug)]
6pub enum ClientError {
7    /// API server error complying with the error schema.
8    Structured(HttpError<GateApiError>),
9    /// API server error not complying with the error schema.
10    Raw(HttpError<String>),
11}
12
13/// Generic Http Error
14#[derive(Debug)]
15pub struct HttpError<T> {
16    /// Http status code
17    pub status_code: u16,
18    /// Response body content
19    pub data: T,
20    /// Response headers
21    pub headers: HashMap<String, String>,
22}
23
24impl<T> HttpError<T> {
25    /// Creates a new HTTP error with status code, data, and headers
26    pub fn new(status_code: u16, data: T, headers: HashMap<String, String>) -> Self {
27        Self {
28            status_code,
29            data,
30            headers,
31        }
32    }
33}
34
35/// Structured Gate server error
36#[derive(Deserialize, Debug)]
37pub struct GateApiError {
38    /// Error code
39    ///
40    /// [API Documentation](https://www.gate.com/docs/developers/apiv4/#accountbook-code)
41
42    /// non-2xx status code
43    #[serde(rename(deserialize = "label"))]
44    pub label: String,
45
46    /// detailed error message
47    #[serde(rename(deserialize = "message"))]
48    pub message: String,
49}