This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-16
Channels
- # aws (6)
- # beginners (129)
- # calva (9)
- # cider (4)
- # cljs-dev (2)
- # clojure (41)
- # clojure-beijing (2)
- # clojure-dev (3)
- # clojure-spec (23)
- # clojure-uk (46)
- # clojurescript (38)
- # community-development (20)
- # core-async (4)
- # cursive (12)
- # data-science (7)
- # datascript (13)
- # datomic (15)
- # duct (11)
- # emacs (18)
- # figwheel-main (5)
- # fulcro (26)
- # off-topic (4)
- # pathom (28)
- # pedestal (3)
- # reagent (8)
- # reitit (6)
- # shadow-cljs (32)
- # specter (3)
I got this to work in the end by hacking together a two-parameter version of reitit.http.coercion/coerce-exceptions-interceptor which returns what i wanted but that doesn't seem like what the official answer ought to be. The arity exception makes me think this is a pedestal / sieppari interceptor mismatch but I can't figure out what I was supposed to use
I'd love to do this the right way (and know where to look in the future) so for reference, here's the hack
(defn my-coerce-exceptions-interceptor
"Interceptor for handling coercion exceptions.
Expects a :coercion of type `reitit.coercion/Coercion`
and :parameters or :responses from route data, otherwise does not mount."
[]
{:name ::coerce-exceptions
:compile (fn [{:keys [coercion parameters responses]} _]
(if (and coercion (or parameters responses))
{:error (fn [ctx ex]
(let [data (ex-data (or (:error ctx)
ex))]
(if-let [status
(case (:type data)
:reitit.coercion/request-coercion 400
:reitit.coercion/response-coercion 500
nil)]
(let [response
{:status status,
:body nil
#_["coercion error"]
#_(coercion/encode-error data)}]
(-> ctx
(assoc :response response)
(assoc :error nil)))
ctx)))}))})
@colliderwriter the arity-error is a pedestal/sieppari thing and documented here: https://metosin.github.io/reitit/http/pedestal.html#compatibility.