This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-13
Channels
- # aleph (5)
- # beginners (92)
- # cider (37)
- # cljs-dev (38)
- # cljsjs (2)
- # cljsrn (3)
- # clojure (50)
- # clojure-berlin (1)
- # clojure-canada (3)
- # clojure-dusseldorf (4)
- # clojure-france (1)
- # clojure-germany (1)
- # clojure-italy (7)
- # clojure-nl (21)
- # clojure-spec (2)
- # clojure-uk (106)
- # clojurescript (165)
- # code-reviews (1)
- # community-development (3)
- # cursive (5)
- # datomic (13)
- # editors (12)
- # emacs (3)
- # figwheel-main (141)
- # fulcro (28)
- # graphql (1)
- # immutant (1)
- # jobs (1)
- # jobs-discuss (5)
- # midje (8)
- # nrepl (3)
- # off-topic (28)
- # onyx (4)
- # re-frame (21)
- # reagent (70)
- # ring (2)
- # ring-swagger (9)
- # shadow-cljs (18)
- # spacemacs (6)
- # specter (23)
- # tools-deps (21)
I am not able to get exceptions to my error-handlers, my api
config map:
{:coercion :spec
:formats (-> muuntaja/default-options
(assoc-in [:formats "application/json" :encoder-opts]
{:encode-key-fn #(name (kebab/->camelCase %))})
(assoc-in [:formats "application/json" :decoder-opts]
{:decode-key-fn #(keyword (kebab/->kebab-case %))}))
:exceptions {:handlers {:error/space-upgrade-not-possible known-exception-handler}}}
no matter what I put in :handlers
the handler functions are not called but they end up into going to default handlers
I wonder if this is a bug caused by spec integration or am I missing something obvious here?
For example, if I replace the :type
based dispatch with exception type and put Exception
it still doesn't do anything
For reference, I have my api setup like this
(defn exception-handler [resp-fn type]
(fn [^Exception e data request]
(resp-fn {:message (.getMessage e)
:type type})))
(def exception-handlers
{:username-conflict (exception-handler conflict :username-conflict)
:email-conflict (exception-handler conflict :email-conflict)})
(defn create-app [{:keys [db]}]
(api
{:exceptions
{:handlers exception-handlers}}
(OPTIONS "/api/*" []
:middleware [mw/cors]
(ok {}))
(GET "/api/" [] (resource-response "index.html" {:root "public"}))
(GET "/api/health" [] (ok {:status "OK"}))
(POST "/api/actions/register" req
:middleware [mw/cors]
(let [_ (core/add-user db (:body-params req))]
(created "/fixme" {:status "OK"})))
(POST "/api/actions/login" req
:middleware [(mw/basic-auth db) mw/cors mw/auth]
(ok (:identity req)))))
And throwing exceptions like this works fine:
(throw (ex-info "Username is already in use!"
{:type :username-conflict}))