This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-01
Channels
- # adventofcode (93)
- # announcements (44)
- # asami (23)
- # aws (1)
- # babashka (48)
- # beginners (112)
- # calva (26)
- # cider (57)
- # clj-kondo (17)
- # cljfx (5)
- # cljs-dev (21)
- # clojure (124)
- # clojure-europe (19)
- # clojure-hungary (40)
- # clojure-nl (3)
- # clojure-spec (7)
- # clojure-uk (3)
- # clojurescript (3)
- # cursive (81)
- # datalog (11)
- # events (21)
- # exercism (1)
- # fulcro (37)
- # graalvm (1)
- # introduce-yourself (8)
- # jobs (1)
- # lsp (1)
- # malli (5)
- # membrane-term (17)
- # minecraft (3)
- # nextjournal (5)
- # off-topic (14)
- # other-lisps (14)
- # polylith (58)
- # reagent (16)
- # reclojure (3)
- # reitit (6)
- # remote-jobs (1)
- # shadow-cljs (55)
- # spacemacs (15)
- # testing (2)
- # tools-build (7)
- # tools-deps (191)
Hey,
Is there a way to customize how request coercion errors are returned in the response?
My use case: I want to return only the :humanized
field, but I’d like to rename it to :errors
.
I know I can use :encode-error
and set it to something like:
(fn [validation-body] {:errors (:humanized validation-body)})
But it’s a waste to create the original errors map just create a new one instead of it.
Ideas?Another question, similar to the above:
Is it possible to return an empty response payload in case of request coercion errors?
My use case: in some routes in prod, I want to hide the validation details, essentially retuning {:status 400}
you can override the coercion errors using the error-middleware options. Don't have an example at hand, docs should cover how to. In not, doc-PR welcome.
What I’m currently doing is adding a field :report-request-coercion-errors?
to the routes.
In the :reitit.coercion/request-coercion
field of the exception middleware, I’m checking if (-> request [:reitit.core/match :data :report-request-coercion-errors?])
and returning either (constantly {:status 400)
or the original (reitit.ring.middleware.exception/create-coercion-handler 400)
.
The downside is that I have to work with :inject-match true
for this work, right?