From 9b3f68ad14a4d0bcb1232a0aec529c03ab1ce316 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 4 Nov 2025 20:33:58 +0100 Subject: [PATCH] :sparkles: Remove unnecesary report on duplicate email error validation --- backend/src/app/db.clj | 6 ++++++ backend/src/app/rpc/commands/auth.clj | 15 ++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/src/app/db.clj b/backend/src/app/db.clj index 4f97f35093..b00f84e3e2 100644 --- a/backend/src/app/db.clj +++ b/backend/src/app/db.clj @@ -704,6 +704,12 @@ (and (sql-exception? cause) (= "40001" (.getSQLState ^java.sql.SQLException cause)))) +(defn duplicate-key-error? + [cause] + (and (sql-exception? cause) + (= "23505" (.getSQLState ^java.sql.SQLException cause)))) + + (extend-protocol jdbc.prepare/SettableParameter clojure.lang.Keyword (set-parameter [^clojure.lang.Keyword v ^PreparedStatement s ^long i] diff --git a/backend/src/app/rpc/commands/auth.clj b/backend/src/app/rpc/commands/auth.clj index f6b81d6add..b223cadb2f 100644 --- a/backend/src/app/rpc/commands/auth.clj +++ b/backend/src/app/rpc/commands/auth.clj @@ -315,16 +315,13 @@ (-> (db/insert! conn :profile params) (profile/decode-row)) (catch org.postgresql.util.PSQLException cause - (let [state (.getSQLState cause)] - (if (not= state "23505") - (throw cause) + (if (db/duplicate-key-error? cause) + (ex/raise :type :validation + :code :email-already-exists + :hint "email already exists" + :cause cause) + (throw cause)))))) - (do - (l/error :hint "not an error" :cause cause) - (ex/raise :type :validation - :code :email-already-exists - :hint "email already exists" - :cause cause)))))))) (defn create-profile-rels! [conn {:keys [id] :as profile}]