diff options
Diffstat (limited to 'src/push/app.rs')
| -rw-r--r-- | src/push/app.rs | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/push/app.rs b/src/push/app.rs index 56b9a02..5e57800 100644 --- a/src/push/app.rs +++ b/src/push/app.rs @@ -8,7 +8,14 @@ use web_push::{ }; use super::repo::Provider as _; -use crate::{login::Login, token::extract::Identity, vapid, vapid::repo::Provider as _}; +use crate::{ + db, + error::failed::{ErrorExt, Failed, ResultExt as _}, + login::Login, + token::extract::Identity, + vapid, + vapid::repo::Provider as _, +}; pub struct Push<P> { db: SqlitePool, @@ -26,9 +33,13 @@ impl<P> Push<P> { subscription: &SubscriptionInfo, vapid: &VerifyingKey, ) -> Result<(), SubscribeError> { - let mut tx = self.db.begin().await?; + let mut tx = self.db.begin().await.fail(db::failed::BEGIN)?; - let current = tx.vapid().current().await?; + let current = tx + .vapid() + .current() + .await + .fail("Failed to load current VAPID key")?; if vapid != ¤t.key { return Err(SubscribeError::StaleVapidKey(current.key)); } @@ -42,7 +53,8 @@ impl<P> Push<P> { let current = tx .push() .by_endpoint(&subscriber.login, &subscription.endpoint) - .await?; + .await + .fail("Failed to load existing subscriptions for endpoint")?; // If we already have a subscription for this endpoint, with _different_ // parameters, then this is a client error. They shouldn't reuse endpoint URLs, // per the various RFCs. @@ -55,12 +67,12 @@ impl<P> Push<P> { return Err(SubscribeError::Duplicate); } } else { - return Err(SubscribeError::Database(err)); + return Err(err.fail("Failed to create push subscription")); } } } - tx.commit().await?; + tx.commit().await.fail(db::failed::COMMIT)?; Ok(()) } @@ -138,10 +150,6 @@ where #[derive(Debug, thiserror::Error)] pub enum SubscribeError { - #[error(transparent)] - Database(#[from] sqlx::Error), - #[error(transparent)] - Vapid(#[from] vapid::repo::Error), #[error("subscription created with stale VAPID key")] StaleVapidKey(VerifyingKey), #[error("subscription already exists for endpoint")] @@ -149,6 +157,8 @@ pub enum SubscribeError { // and we want to limit its proliferation. The only intended recipient of this message is the // client, which already knows the endpoint anyways and doesn't need us to tell them. Duplicate, + #[error(transparent)] + Failed(#[from] Failed), } #[derive(Debug, thiserror::Error)] |
