Skip to content

Commit

Permalink
fix: uniformly format exceptions for the client
Browse files Browse the repository at this point in the history
Not 100% sure this is the best idea, but nothing server side should be
secret so this should be fine?
  • Loading branch information
Akeboshiwind committed Mar 15, 2024
1 parent ff10e2e commit 01e9373
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,26 @@
(s/def ::query string?)
(s/def ::db-run (s/keys :req-un [::txs ::query]))

(defn- handle-ex-info [ex req]
{:status 400,
(defn- handle-client-error [ex _]
{:status 400
:body {:message (ex-message ex)
:exception (.getClass ex)
:data (ex-data ex)
:uri (:uri req)}})
:data (ex-data ex)}})

(defn- handle-other-error [ex _]
{:status 500
:body {:message (ex-message ex)
:exception (.getClass ex)
:data (ex-data ex)}})

(def exception-middleware
(exception/create-exception-middleware
(merge
exception/default-handlers
{xtdb.IllegalArgumentException handle-ex-info
xtdb.RuntimeException handle-ex-info})))
{xtdb.IllegalArgumentException handle-client-error
xtdb.RuntimeException handle-client-error
clojure.lang.ExceptionInfo handle-client-error
::exception/default handle-other-error})))

(def xt-version
(-> (slurp "deps.edn")
Expand Down

0 comments on commit 01e9373

Please sign in to comment.