Skip to content

Commit

Permalink
[Tunnelbroker] deprecate errors about invalidating device token
Browse files Browse the repository at this point in the history
Summary: [ENG-9573](https://linear.app/comm/issue/ENG-9573/alarm-tunnelbrokerstagingfcmerroralarm-in-us-east-ohio).

Test Plan: Invalidating token still works but not causing errors

Reviewers: bartek, will

Reviewed By: bartek

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D13659
  • Loading branch information
xsanm committed Oct 9, 2024
1 parent a64fc62 commit 6f0c5fa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
22 changes: 14 additions & 8 deletions services/tunnelbroker/src/notifs/fcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,20 @@ impl FCMClient {
.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));
}
}
Expand Down
7 changes: 7 additions & 0 deletions services/tunnelbroker/src/notifs/fcm/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,11 @@ impl FCMErrorResponse {
_ => FCMErrorResponse::UnspecifiedError,
}
}

pub fn should_invalidate_token(&self) -> bool {
matches!(
self,
FCMErrorResponse::Unregistered | FCMErrorResponse::InvalidArgument(_)
)
}
}
7 changes: 1 addition & 6 deletions services/tunnelbroker/src/websockets/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::constants::{
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;
Expand Down Expand Up @@ -600,11 +599,7 @@ impl<S: AsyncRead + AsyncWrite + Unpin> WebsocketSession<S> {
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
Expand Down

0 comments on commit 6f0c5fa

Please sign in to comment.