Fork me on GitHub
#clojure-spec
<
2022-03-01
>
zendevil.eth11:03:46

can someone explain to me why I’m seeing this error?

"res is " {:response {:status 400, :body "{\"spec\":\"(spec-tools.core/spec {:spec (clojure.spec.alpha/keys :req-un [:spec$34944/timezone :spec$34944/name]), :type :map, :leaf? false})\",\"problems\":[{\"path\":[],\"pred\":\"clojure.core/map?\",\"val\":null,\"via\":[],\"in\":[]}],\"type\":\"reitit.coercion/request-coercion\",\"coercion\":\"spec\",\"value\":null,\"in\":[\"request\",\"body-params\"]}", :headers {"Content-Type" "application/json; charset=utf-8", "X-XSS-Protection" "1; mode=block", "X-Frame-Options" "SAMEORIGIN", "X-Content-Type-Options" "nosniff"}}, :request {:protocol "HTTP/1.1", :remote-addr "127.0.0.1", :headers {"host" "localhost", "content-type" "application/x-www-form-urlencoded", "content-length" "39"}, :server-port 80, :content-length 39, :content-type "application/x-www-form-urlencoded", :uri "/api/schools", :server-name "localhost", :body #object[java.io.BufferedInputStream 0x79432e4b "java.io.BufferedInputStream@79432e4b"], :scheme :http, :request-method :post}, :headers nil, :app #ob}
I’m making the request like so:
(require '[peridot.core :refer [content-type request session])

(-> session
      (request "/api/schools"
               :params {:name name
                        :timezone (or timezone "America/New_York")}
                                    
               :request-method :post))
this is my reitit handler:
["/schools" {:swagger {:tags ["schools"]}}
   ["" {:post {:description "create a school"
               :parameters {:body {:timezone string?
                                   :name string?}}
               :handler create-school-handler}}]
...]
FYI I have these three middleware ([reitit.ring.coercion :as rrc]):
rrc/coerce-exceptions-middleware
rrc/coerce-request-middleware
rrc/coerce-response-middleware

zendevil.eth11:03:12

I don’t see the error when I remove the middleware

seancorfield19:03:47

@ps Based on \"pred\":\"clojure.core/map?\",\"val\":null -- it's saying that it got null via JSON but expected a (non-nil) hash map, if I'm reading it correctly. Maybe ask in #reitit?

zendevil.eth20:03:42

@seancorfield why would it get null via json? When I remove the coerce middleware, the params are right there in the handler

seancorfield20:03:46

No idea. That's why I suggested asking in #reitit (which I do not use).

seancorfield20:03:12

(since it seems to be related to the reitit middleware, more than Spec)