This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-13
Channels
- # admin-announcements (1)
- # announcements (40)
- # aws (2)
- # babashka (46)
- # babashka-sci-dev (106)
- # beginners (31)
- # cider (5)
- # circleci (2)
- # clj-kondo (48)
- # clojure (118)
- # clojure-belgium (1)
- # clojure-chicago (3)
- # clojure-europe (19)
- # clojure-ireland (3)
- # clojure-losangeles (2)
- # clojure-nl (2)
- # clojure-spec (10)
- # clojure-uk (4)
- # clojurescript (18)
- # community-development (5)
- # core-async (159)
- # cursive (16)
- # datomic (16)
- # etaoin (1)
- # fulcro (21)
- # funcool (14)
- # graalvm (5)
- # gratitude (4)
- # holy-lambda (28)
- # jobs (1)
- # jobs-discuss (1)
- # kaocha (1)
- # lsp (12)
- # malli (21)
- # meander (12)
- # music (1)
- # off-topic (8)
- # portal (5)
- # react (18)
- # reitit (1)
- # releases (4)
- # remote-jobs (1)
- # shadow-cljs (56)
- # timbre (4)
Hi guys, how are you? I am new to Clojure. I wanted to ask a question about humanizing the errors returned from Malli when used as coercion. I tried to do like below, but it didn't work.
(def custom-coercion (reitit.coercion.malli/create
{:transformers {:body {:default reitit.coercion.malli/default-transformer-provider
:formats {"application/json" reitit.coercion.malli/json-transformer-provider}}
:string {:default reitit.coercion.malli/string-transformer-provider}
:response {:default reitit.coercion.malli/default-transformer-provider}}
:error-keys #{:type :coercion :in :schema :value :errors :humanized #_:transformed}
:compile mu/closed-schema
:encode-error (fn [error] {:errors (:humanized error)})
:validate true
:enabled true
:strip-extra-keys true
:default-values true
:options nil}))
Thank @dharrigan. I appreciate it.
The encode-error
function can be certainly improved (it assumes only one error, there could be multiple). Treat it like a starting point 😉
❯ http :8080/api/foo
HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
What is going on?? There is a 'missing required key'. I was expecting a value for '[:id]' but got 'null' instead!
❯ http :8080/api/foo?id=10
HTTP/1.1 200 OK
Content-Length: 14
Content-Type: application/json;charset=utf-8
{
"hello": "10"
}
Thank you. I am checking it now
Thanks buddy. By the way, you can put also this :error-keys #{:type :coercion :in :schema :value :errors :humanized #_:transformed} in order to get a humanized key that you can use in the encode-error