This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-01
Channels
- # aleph (1)
- # announcements (2)
- # aws (3)
- # bangalore-clj (1)
- # beginners (136)
- # boot (3)
- # calva (89)
- # cider (44)
- # cljdoc (1)
- # cljs-dev (31)
- # clojure (101)
- # clojure-europe (3)
- # clojure-italy (52)
- # clojure-nl (7)
- # clojure-spec (12)
- # clojure-uk (34)
- # clojurescript (62)
- # community-development (46)
- # cursive (25)
- # datomic (6)
- # duct (26)
- # events (6)
- # figwheel-main (4)
- # fulcro (25)
- # graphql (2)
- # jackdaw (4)
- # jukebox (3)
- # kaocha (57)
- # leiningen (31)
- # off-topic (3)
- # onyx (4)
- # other-languages (22)
- # pathom (18)
- # re-frame (9)
- # reitit (3)
- # shadow-cljs (60)
- # spacemacs (9)
- # speculative (22)
- # sql (39)
- # tools-deps (45)
- # vim (37)
I’m setting up coercion, but I’m running into an exception. According to the docs:
The coercion middleware are compiled againts a route. In the middleware compilation step the actual coercer implementations are constructed for the defined models. Also, the middleware doesn't mount itself if a route doesn't have :coercion and :parameters or :responses defined.
So I should be able to declare routes like this:
(def routes
[
[""
{:middleware [:app.middleware/coerce-request
:app.middleware/coerce-response
:app.middleware/coerce-exceptions
:app.middleware/defaults]}
["/" ::home-page]]
;; More routes here that actually have coercions...
])
I make sure to pass in a map for :reitit.middleware/registry that includes the referenced middlewares.
Still, when the routes are created and compiled, I get an exception claiming the middleware is not in the registry:
clojure.lang.ExceptionInfo: Middleware :app.middleware/coerce-request not found in registry.
Available middleware in registry:
| :id | :description |
|--------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| :app.middleware/coerce-request | {:name :reitit.ring.coercion/coerce-request, :spec :reitit.spec/parameters, :compile #object[reitit.ring.coercion$fn__172563 0x194605f7 "reitit.ring.coercion$fn__172563@194605f7"]} |
| :app.middleware/coerce-response | {:name :reitit.ring.coercion/coerce-response, :spec :reitit.spec/responses, :compile #object[reitit.ring.coercion$fn__56703 0x36e4e57e "reitit.ring.coercion$fn__56703@36e4e57e"]} |
| :app.middleware/coerce-exceptions | {:name :reitit.ring.coercion/coerce-exceptions, :compile #object[reitit.ring.coercion$fn__56716 0x7a95f7d4 "reitit.ring.coercion$fn__56716@7a95f7d4"]} |
| :app.middleware/defaults | {:name :app.middleware/wrap-defaults, :wrap #object[app.middleware$fn__212347 0x6b916d5 "app.middleware$fn__212347@6b916d5"]} |
It fails when compiling the ::home-page route, which does not have any coercion. Hence the coerce-request compile function returns nil, which causes into-middleware to throw.
What am I missing here?