1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use serde::Deserialize;
use thiserror::Error;

#[derive(Clone, Debug, Deserialize)]
pub struct FireBaseAPIErrorDetail {
    pub message: String,
    pub reason: String,
    pub domain: String,
}

#[derive(Clone, Debug, Deserialize)]
pub struct FireBaseAPIError {
    pub code: u16,
    pub message: String,
    pub errors: Vec<FireBaseAPIErrorDetail>,
}

/// [Firebase Auth error response body](https://firebase.google.com/docs/reference/rest/auth#section-error-format)
#[derive(Clone, Debug, Deserialize)]
pub struct FireBaseAPIErrorResponse {
    pub error: FireBaseAPIError,
}

#[derive(Error, Debug, Clone)]
pub enum ApiClientError {
    #[error("Failed to send API request")]
    FailedToSendRequest,
    #[error("Failed to serialize API request")]
    FailedToSerializeRequest,
    #[error("Failed to receive API response")]
    FailedToReceiveResponse,
    #[error("Failed to deserialize API response")]
    FailedToDeserializeResponse,
    #[error("Server responded with an error {0:?}")]
    ServerError(FireBaseAPIError),
}