diff --git a/src/application/services/auth.rs b/src/application/services/auth.rs index d956c29..5447f21 100644 --- a/src/application/services/auth.rs +++ b/src/application/services/auth.rs @@ -132,7 +132,15 @@ impl AuthService { .bind(&req.email) .bind(&hashed) .fetch_one(&mut *tx) - .await?; + .await + .map_err(|e| { + if let sqlx::Error::Database(db) = &e + && db.is_unique_violation() + { + return AppError::AlreadyExists("User already exists".into()); + } + e.into() + })?; let user_count: i64 = sqlx::query_scalar("SELECT COUNT(1) FROM users WHERE tenant_id = $1") .bind(tenant_id) @@ -412,4 +420,3 @@ impl AuthService { }) } } -