firebae_cm/client/
response.rs

1/// A Firebase Cloud Message Error. For example, an invalid JWT token would return the following error:
2/// ```
3/// FcmError {
4///     code: 401,
5///     message: "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
6///     status: "UNAUTHENTICATED"
7/// }
8/// ```
9#[derive(serde::Deserialize, thiserror::Error, Debug)]
10pub struct FcmError {
11    pub code: u16,
12    pub message: String,
13    pub status: String,
14}
15
16impl std::fmt::Display for FcmError {
17    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
18        write!(f, "{} ({}): {}", self.status, self.code, self.message)
19    }
20}
21
22/// Represents a response by Firebase, whether it is successful or an error.
23#[derive(serde::Deserialize, Debug)]
24pub enum FcmResponse {
25    #[serde(rename = "name")]
26    Success(String),
27    #[serde(rename = "error")]
28    Error(FcmError),
29}