Fork me on GitHub
#luminus
<
2017-06-14
>
v3ga00:06:03

Hi, i’m going through web development in clojure 2nd edition and I can’t figure out why i’m getting a http 412 error https://gist.github.com/anonymous/2428913e718c68e6bc64cf4c261c12e9

yogthos02:06:47

it looks like there is an extra set of parens here:

((try
     (db/create-user!
       (-> user
           (dissoc :pass-confirm)
           (update :pass hashers/encrypt)))
     (-> {:result :ok}
         (response/ok)
         (assoc :session (assoc session :identity (:id user))))
     (catch Exception e
       (handle-registration-error e))))

yogthos03:06:24

should just be:

(defn register! [{:keys [session]} user]
  (if (registration-errors user)
    (response/precondition-failed {:result :error})
    (try
      (db/create-user!
        (-> user
            (dissoc :pass-confirm)
            (update :pass hashers/encrypt)))
      (-> {:result :ok}
          (response/ok)
          (assoc :session (assoc session :identity (:id user))))
      (catch Exception e
        (handle-registration-error e)))))

v3ga06:06:03

@yogthos Ok, I removed that extra set of parenthesis and I got the same error. I also ran ‘lein clean’, ‘lein deps’ then restarting my repl in hopes of clearing everything out

rebel07:06:05

BTW (.startsWith "ERROR: duplicate key value") PG error depends on system local language, is there a language agnostic solution to catch an error?

v3ga08:06:56

good question.

rebel11:06:10

I've just added or and included my local, but it looks like wooden crutch

yogthos12:06:44

it looks like you do have to handle errors in a database dependent fashion, other approach would be to do a select in a transaction to see if a record with the same name is there