Skip to content

Commit

Permalink
fix: remove device tokens on any errors
Browse files Browse the repository at this point in the history
410 case seems to be dead code because 410 errors are actually
returned as Err case, not Ok.

There are also errors 400 according to the log.
  • Loading branch information
link2xt committed Feb 22, 2024
1 parent eaf89f8 commit def00a5
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/notifier.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use a2::{
Client, Endpoint, NotificationBuilder, NotificationOptions, Priority, SilentNotificationBuilder,
Client, Endpoint, Error::ResponseError, NotificationBuilder, NotificationOptions, Priority,
SilentNotificationBuilder,
};
use anyhow::Result;
use async_std::prelude::*;
Expand Down Expand Up @@ -55,22 +56,18 @@ async fn wakeup(db: &sled::Db, client: &Client, topic: Option<&str>) {
);

match client.send(payload).await {
Ok(res) => {
match res.code {
200 => {
info!("delivered notification for {}", device_token);
}
410 => {
// no longer active
if let Err(err) = db.remove(&device_token) {
error!("failed to remove {}: {:?}", &device_token, err);
} else {
info!("removed inactive token: {}", &device_token);
}
}
_ => {
warn!("unexpected status: {:?}", res);
}
Ok(res) => match res.code {
200 => {
info!("delivered notification for {}", device_token);
}
_ => {
warn!("unexpected status: {:?}", res);
}
},
Err(ResponseError(res)) => {
info!("Removing token {} due to error {:?}.", &device_token, res);
if let Err(err) = db.remove(&device_token) {
error!("failed to remove {}: {:?}", &device_token, err);
}
}
Err(err) => {
Expand Down

0 comments on commit def00a5

Please sign in to comment.