Open mjhanninen opened 4 years ago
This seems like a bug to me. Fixing it would be a minor breaking change. As a workaround, users could include a middleware like this in their pipeline before coercion:
(defn convert-exceptions-to-async-middleware
[handler]
(fn
([request] (hander request))
([request respond raise]
(try
(handler request respond raise)
(catch #?(:clj Exception :cljs js/Error) e
(raise e))))))
The
coerce-exceptions-middleware
converts thrownException
s that are unrelated to coercion failures (for example, anArithmeticException
) into asynchronous failures terminating their stack unwinding process too early. This happens is becausecoercion-exception-handler
is passed the asynchronous failure callbackraise
(instead of, say,#(throw %)
) on the line 87 of the following snippet:https://github.com/metosin/reitit/blob/43e1a520d60aefa6bd7c67316b92f170c1e6d447/modules/reitit-ring/src/reitit/ring/coercion.cljc#L84-L87