diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-10-11 22:57:56 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-10-11 22:57:56 -0400 |
| commit | 756863f298f9e4277863f9e8758e253c5ae95923 (patch) | |
| tree | 82a9c6643b360b035f4630f2b1db138d9937c8d8 /src/invite | |
| parent | 812f1cafe3f8a68bf45b677fade7417c30d92eac (diff) | |
Return a distinct error when an invite username is in use.
I've also aligned channel creation with this (it's 409 Conflict). To make server setup more distinct, it now returns 503 Service Unavailable if setup has not been completed.
Diffstat (limited to 'src/invite')
| -rw-r--r-- | src/invite/app.rs | 10 | ||||
| -rw-r--r-- | src/invite/routes.rs | 3 |
2 files changed, 11 insertions, 2 deletions
diff --git a/src/invite/app.rs b/src/invite/app.rs index 998b4f1..6800d72 100644 --- a/src/invite/app.rs +++ b/src/invite/app.rs @@ -4,7 +4,7 @@ use sqlx::sqlite::SqlitePool; use super::{repo::Provider as _, Id, Invite, Summary}; use crate::{ clock::DateTime, - db::NotFound as _, + db::{Duplicate as _, NotFound as _}, event::repo::Provider as _, login::{repo::Provider as _, Login, Password}, token::{repo::Provider as _, Secret}, @@ -68,7 +68,11 @@ impl<'a> Invites<'a> { // catch it. tx.invites().accept(&invite).await?; let created = tx.sequence().next(accepted_at).await?; - let login = tx.logins().create(name, &password_hash, &created).await?; + let login = tx + .logins() + .create(name, &password_hash, &created) + .await + .duplicate(|| AcceptError::DuplicateLogin(name.into()))?; let secret = tx.tokens().issue(&login, accepted_at).await?; tx.commit().await?; @@ -99,6 +103,8 @@ pub enum Error { pub enum AcceptError { #[error("invite not found: {0}")] NotFound(Id), + #[error("name in use: {0}")] + DuplicateLogin(String), #[error(transparent)] Database(#[from] sqlx::Error), #[error(transparent)] diff --git a/src/invite/routes.rs b/src/invite/routes.rs index 3384e10..977fe9b 100644 --- a/src/invite/routes.rs +++ b/src/invite/routes.rs @@ -88,6 +88,9 @@ impl IntoResponse for AcceptError { let Self(error) = self; match error { error @ app::AcceptError::NotFound(_) => NotFound(error).into_response(), + error @ app::AcceptError::DuplicateLogin(_) => { + (StatusCode::CONFLICT, error.to_string()).into_response() + } other => Internal::from(other).into_response(), } } |
