Remove unnecesary report on duplicate email error validation

This commit is contained in:
Andrey Antukh
2025-11-04 20:33:58 +01:00
parent c850f101d3
commit 9b3f68ad14
2 changed files with 12 additions and 9 deletions

View File

@@ -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]

View File

@@ -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)
(do
(l/error :hint "not an error" :cause cause)
(if (db/duplicate-key-error? cause)
(ex/raise :type :validation
:code :email-already-exists
:hint "email already exists"
:cause cause))))))))
:cause cause)
(throw cause))))))
(defn create-profile-rels!
[conn {:keys [id] :as profile}]