summaryrefslogtreecommitdiff
path: root/src/push
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-11-25 21:02:25 -0500
committerOwen Jacobson <owen@grimoire.ca>2025-11-25 21:02:25 -0500
commit664e3beba053aee50fc6b3cdcc6ee0dfe5e0fe1f (patch)
tree096b997d56959dd88d099f4f96a383daa4dbc39a /src/push
parent91c33501a315abe04aeed54aa27388ce0ad241ce (diff)
parent33601ef703a640b57e5bd0bf7dbd6d7ffa7377bf (diff)
Merge branch 'house-of-failed'
Diffstat (limited to 'src/push')
-rw-r--r--src/push/app.rs30
-rw-r--r--src/push/handlers/subscribe/mod.rs2
2 files changed, 21 insertions, 11 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 != &current.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)]
diff --git a/src/push/handlers/subscribe/mod.rs b/src/push/handlers/subscribe/mod.rs
index a1a5899..6dcab06 100644
--- a/src/push/handlers/subscribe/mod.rs
+++ b/src/push/handlers/subscribe/mod.rs
@@ -81,7 +81,7 @@ impl IntoResponse for Error {
app::SubscribeError::Duplicate => {
(StatusCode::CONFLICT, err.to_string()).into_response()
}
- other => Internal::from(other).into_response(),
+ app::SubscribeError::Failed(_) => Internal::from(err).into_response(),
}
}
}