Skip to main content

firebase_admin_sdk/core/
mod.rs

1pub mod middleware;
2
3use serde::Deserialize;
4
5#[derive(Debug, Deserialize)]
6pub struct FirebaseErrorResponse {
7    pub error: FirebaseErrorDetails,
8}
9
10#[derive(Debug, Deserialize)]
11pub struct FirebaseErrorDetails {
12    pub code: u16,
13    pub message: String,
14    pub status: Option<String>,
15    pub errors: Option<Vec<FirebaseSubError>>,
16}
17
18#[derive(Debug, Deserialize)]
19pub struct FirebaseSubError {
20    pub message: String,
21    pub domain: Option<String>,
22    pub reason: Option<String>,
23}
24
25impl FirebaseErrorResponse {
26    pub fn display_message(&self) -> String {
27        format!("{} (code: {})", self.error.message, self.error.code)
28    }
29}
30
31pub async fn parse_error_response(response: reqwest::Response, default_msg: &str) -> String {
32    let status = response.status();
33    match response.json::<FirebaseErrorResponse>().await {
34        Ok(error_resp) => error_resp.display_message(),
35        Err(_) => format!("{}: {}", default_msg, status),
36    }
37}