diff --git a/services/tunnelbroker/src/notifs/fcm/error.rs b/services/tunnelbroker/src/notifs/fcm/error.rs index 4197782f9..69f5a5956 100644 --- a/services/tunnelbroker/src/notifs/fcm/error.rs +++ b/services/tunnelbroker/src/notifs/fcm/error.rs @@ -1,16 +1,18 @@ +use crate::notifs::fcm::response::FCMError; use derive_more::{Display, Error, From}; #[derive(Debug, From, Display, Error)] pub enum Error { JWTError, ReqwestError(reqwest::Error), InvalidHeaderValue(reqwest::header::InvalidHeaderValue), SerdeJson(serde_json::Error), FCMTokenNotInitialized, + FCMError(FCMError), } impl From for Error { fn from(_: jsonwebtoken::errors::Error) -> Self { Self::JWTError } } diff --git a/services/tunnelbroker/src/notifs/fcm/mod.rs b/services/tunnelbroker/src/notifs/fcm/mod.rs index 6e9def31c..6666e916b 100644 --- a/services/tunnelbroker/src/notifs/fcm/mod.rs +++ b/services/tunnelbroker/src/notifs/fcm/mod.rs @@ -1,32 +1,33 @@ use crate::notifs::fcm::config::FCMConfig; use crate::notifs::fcm::token::FCMToken; use std::time::Duration; pub mod config; mod error; mod firebase_message; +mod response; mod token; #[derive(Clone)] pub struct FCMClient { http_client: reqwest::Client, config: FCMConfig, token: FCMToken, } impl FCMClient { pub fn new(config: &FCMConfig) -> Result { let http_client = reqwest::Client::builder().build()?; // Token must be a short-lived token (60 minutes) and in a reasonable // timeframe. let token_ttl = Duration::from_secs(60 * 55); let token = FCMToken::new(&config.clone(), token_ttl)?; Ok(FCMClient { http_client, config: config.clone(), token, }) } } diff --git a/services/tunnelbroker/src/notifs/fcm/response.rs b/services/tunnelbroker/src/notifs/fcm/response.rs new file mode 100644 index 000000000..190d3e93f --- /dev/null +++ b/services/tunnelbroker/src/notifs/fcm/response.rs @@ -0,0 +1,44 @@ +use derive_more::{Display, Error}; + +#[derive(PartialEq, Debug, Clone, Display, Error)] +pub struct InvalidArgumentError { + pub details: String, +} +#[derive(PartialEq, Debug, Display, Error)] +pub enum FCMError { + /// No more information is available about this error. + UnspecifiedError, + + /// HTTP error code = 400. + /// Request parameters were invalid. + /// Potential causes include invalid registration, invalid package name, + /// message too big, invalid data key, invalid TTL, or other invalid + /// parameters. + InvalidArgument(InvalidArgumentError), + + /// HTTP error code = 404. + /// App instance was unregistered from FCM. This usually means that + /// the token used is no longer valid and a new one must be used. + Unregistered, + + /// HTTP error code = 403. + /// The authenticated sender ID is different from the sender ID for + /// the registration token. + SenderIdMismatch, + + /// HTTP error code = 429. + /// Sending limit exceeded for the message target. + QuotaExceeded, + + /// HTTP error code = 503. + /// The server is overloaded. + Unavailable, + + /// HTTP error code = 500. + /// An unknown internal error occurred. + Internal, + + /// HTTP error code = 401. + /// APNs certificate or web push auth key was invalid or missing. + ThirdPartyAuthError, +}