From e29926a62bcd048d321bdfd796a5c0ceb4faa3c4 Mon Sep 17 00:00:00 2001 From: shay7sev Date: Mon, 9 Feb 2026 19:52:01 +0800 Subject: [PATCH] fix(service): fix register --- src/application/services/auth.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 { }) } } -