Fork me on GitHub
#reitit
<
2022-07-18
>
plins14:07:55

any news on that? https://github.com/metosin/reitit/issues/420 Im having some super strange behaviour when passing an invalid body, instead of getting a 400 Im not even able to intercept the exception when making a request

valtteri18:07:12

I’m not a Pedestal expert but I could figure out that the exception/exception-interceptor is not compatible with Pedestal exception handling. It doesn’t know how to pick up the error from :io.pedestal.interceptor.chain/error key in ctx . I tried replacing the exception interceptor with something like this

{:error (fn [ctx ex]
          (assoc ctx :response {:status 400
                                :body "error horror"}))}
and it worked as one would expect. Pedestal exception fn is described in http://pedestal.io/reference/error-handling ex contains the exception caught by Pedestal wrapped into ex-info. You could decide based on the exception what to return. I hope this helps you forward building a more robust error handler. We could and probably should improve the pedestal module by adding a working error handler. However I at least need to get more familiar with Pedestal.. Or we wait for Tommi to come back from holidays. 🙂 Also PR’s are warmly welcome!

plins14:08:33

Im trying to see if I can fix this but the error appears to be at reitit.http.coercion/coerce-request thats what the stacktrace is telling me I tried to modify exception/exception-interceptor to check for :io.pedestal.interceptor.chain/error in the ctx but the error happens before that

plins11:09:05

hey @U055NJ5CC sorry to ping you on this, but could you point me to a place in the code so I can try to open a PR fixing it? right now its impossible to use pedestal + spec + reitit

Shivam A12:11:12

@U3QUAHZJ6 @U6N4HSMFW I am facing same exception when I try to reitit.coercion.specs with pedestal and reitit. The problem is not in pedestal or reitit the problem is in muuntaja/format-response-interceptor interceptor. Basically muuntaja/encodes (used inside format-response-interceptor) doesn't know how to serialise reitit.coercion.spec class. The trace in exception "No serializer found for class clojure.spec.alpha$map_spec_impl$reify__1997"confirms that. The quick and easy workaround I found is to replace reitit.coercion.spec with reitit.coercion.malli (for validation) . Then everything works as expected.

👍 1