diff --git a/services/tunnelbroker/src/notifs/fcm/mod.rs b/services/tunnelbroker/src/notifs/fcm/mod.rs --- a/services/tunnelbroker/src/notifs/fcm/mod.rs +++ b/services/tunnelbroker/src/notifs/fcm/mod.rs @@ -86,14 +86,20 @@ .text() .await .unwrap_or_else(|error| format!("Error occurred: {}", error)); - error!( - errorType = error_types::FCM_ERROR, - "Failed sending FCM notification to: {}. Status: {}. Body: {}", - token, - error_status, - body - ); - let fcm_error = FCMErrorResponse::from_status(error_status, body); + + let fcm_error = + FCMErrorResponse::from_status(error_status, body.clone()); + + if !fcm_error.should_invalidate_token() { + error!( + errorType = error_types::FCM_ERROR, + "Failed sending FCM notification to: {}. Status: {}. Body: {}", + token, + error_status, + body + ); + } + return Err(FCMError(fcm_error)); } } diff --git a/services/tunnelbroker/src/notifs/fcm/response.rs b/services/tunnelbroker/src/notifs/fcm/response.rs --- a/services/tunnelbroker/src/notifs/fcm/response.rs +++ b/services/tunnelbroker/src/notifs/fcm/response.rs @@ -60,4 +60,11 @@ _ => FCMErrorResponse::UnspecifiedError, } } + + pub fn should_invalidate_token(&self) -> bool { + matches!( + self, + FCMErrorResponse::Unregistered | FCMErrorResponse::InvalidArgument(_) + ) + } } diff --git a/services/tunnelbroker/src/websockets/session.rs b/services/tunnelbroker/src/websockets/session.rs --- a/services/tunnelbroker/src/websockets/session.rs +++ b/services/tunnelbroker/src/websockets/session.rs @@ -3,7 +3,6 @@ error_types, CLIENT_RMQ_MSG_PRIORITY, DDB_RMQ_MSG_PRIORITY, MAX_RMQ_MSG_PRIORITY, RMQ_CONSUMER_TAG, }; -use crate::notifs::fcm::response::FCMErrorResponse; use crate::notifs::wns::response::WNSErrorResponse; use comm_lib::aws::ddb::error::SdkError; use comm_lib::aws::ddb::operation::put_item::PutItemError; @@ -600,11 +599,7 @@ let result = fcm.send(fcm_message).await; if let Err(NotifsFCMError(fcm_error)) = &result { - if matches!( - fcm_error, - FCMErrorResponse::Unregistered - | FCMErrorResponse::InvalidArgument(_) - ) { + if fcm_error.should_invalidate_token() { if let Err(e) = self .invalidate_device_token(notif.device_id, device_token.clone()) .await