diff --git a/services/tunnelbroker/src/notifs/wns/mod.rs b/services/tunnelbroker/src/notifs/wns/mod.rs --- a/services/tunnelbroker/src/notifs/wns/mod.rs +++ b/services/tunnelbroker/src/notifs/wns/mod.rs @@ -69,14 +69,19 @@ .text() .await .unwrap_or_else(|error| format!("Error occurred: {}", error)); - tracing::error!( - errorType = error_types::WNS_ERROR, - "Failed sending WNS notification to: {}. Status: {}. Body: {}", - &url, - error_status, - body - ); - let wns_error = WNSErrorResponse::from_status(error_status, body); + let wns_error = + WNSErrorResponse::from_status(error_status, body.clone()); + + if !wns_error.should_invalidate_token() { + tracing::error!( + errorType = error_types::WNS_ERROR, + "Failed sending WNS notification to: {}. Status: {}. Body: {}", + &url, + error_status, + body + ); + } + Err(error::Error::WNSNotification(wns_error)) } } diff --git a/services/tunnelbroker/src/notifs/wns/response.rs b/services/tunnelbroker/src/notifs/wns/response.rs --- a/services/tunnelbroker/src/notifs/wns/response.rs +++ b/services/tunnelbroker/src/notifs/wns/response.rs @@ -74,4 +74,7 @@ _ => WNSErrorResponse::UnspecifiedError, } } + pub fn should_invalidate_token(&self) -> bool { + matches!(self, WNSErrorResponse::NotFound | WNSErrorResponse::Gone) + } } 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::wns::response::WNSErrorResponse; use comm_lib::aws::ddb::error::SdkError; use comm_lib::aws::ddb::operation::put_item::PutItemError; use derive_more; @@ -715,8 +714,7 @@ let result = wns_client.send(wns_notif).await; if let Err(NotifsWNSError(err)) = &result { - if matches!(err, WNSErrorResponse::NotFound | WNSErrorResponse::Gone) - { + if err.should_invalidate_token() { if let Err(e) = self .invalidate_device_token(notif.device_id, device_token.clone()) .await