diff --git a/services/tunnelbroker/rust-notifications/src/apns.rs b/services/tunnelbroker/rust-notifications/src/apns.rs --- a/services/tunnelbroker/rust-notifications/src/apns.rs +++ b/services/tunnelbroker/rust-notifications/src/apns.rs @@ -2,7 +2,7 @@ Client, Endpoint, NotificationBuilder, NotificationOptions, PlainNotificationBuilder, }; -use anyhow::Result; +use anyhow::{anyhow, Result}; use std::fs::File; pub async fn send_by_a2_client( @@ -11,7 +11,7 @@ device_token: &str, message: &str, sandbox: bool, -) -> Result { +) -> Result<()> { let mut certificate = File::open(certificate_path)?; let endpoint = if sandbox { Endpoint::Sandbox @@ -26,5 +26,11 @@ let builder = PlainNotificationBuilder::new(message); let payload = builder.build(device_token, options); let response = client.send(payload).await?; - Ok(response.code) + if response.code != 200 { + return Err(anyhow!( + "Client returned HTTP error status code: {:?}", + response.code + )); + } + Ok(()) } diff --git a/services/tunnelbroker/rust-notifications/src/lib.rs b/services/tunnelbroker/rust-notifications/src/lib.rs --- a/services/tunnelbroker/rust-notifications/src/lib.rs +++ b/services/tunnelbroker/rust-notifications/src/lib.rs @@ -14,7 +14,7 @@ device_token: &str, message: &str, sandbox: bool, - ) -> Result; + ) -> Result<()>; #[cxx_name = "sendNotifToFCM"] fn send_notif_to_fcm( @@ -37,7 +37,7 @@ device_token: &str, message: &str, sandbox: bool, -) -> Result { +) -> Result<()> { RUNTIME.block_on(apns::send_by_a2_client( certificate_path, certificate_password,