If my compojure-api API gives a 500 with a path containing spaces e.g /api/foo/some id with spaces
, is that a bug in the library or something I've not done as a developer? (perhaps added some ring middleware?)
@mgrbyte good question, haven't seen that. Could you test that with plain Compojure? 500 sounds odd thou.
Just tracked it down. Have a custom error handler which tries to turn spec errors into an error message with bad-request
. spec validation error couldn't be written to stream, so answered my own question.
😞
tracked down exactly the cause. My error handler uses a small function to encode the response:
(defn respond-with [response-fn request data]
(let [fmt (-> request
:compojure.api.request/muuntaja
:default-format)]
(-> data
(response-fn)
(content-type fmt))))
For some reason, :default-format
in this case, is nil
, causing the 500 error (cannot write persistentarraymap). It works in most other cases :thinking_face:In fact, (:compojure.api.request/muuntaja request)
is nil.
@ikitommi I see from compojure-api's path-for*
function that this might happen - I'm guessing there are cases where the muuntaja instance might not present in the request, and one has define another default?
https://github.com/metosin/compojure-api/blob/5aee5b40a8477bb37557f624237395e573bf0a12/src/compojure/api/routes.clj#L229