Hi. Can anybody point me to a good example for understanding async Ring handlers and middleware? Esp raising exceptions.
In the middleware, do I need to catch any exceptions and call (raise thrown)
?
For example, in the middleware below:
(defn ping-middleware
([handler]
(ping-middleware handler #{"/ping" "/ping/"}))
([handler ping-uris]
(ping-middleware handler ping-uris (constantly "pong")))
([handler ping-uris body-generator]
(let [ping-uris-set (set ping-uris)
ping-response (fn [] {:status 200
:body (body-generator)
:headers {"Content-Type" "text/plain"
"Cache-Control" "no-store, no-cache, must-revalidate"}})]
(fn
([request]
(if (->> (:uri request)
(contains? ping-uris-set))
(ping-response)
(handler request)))
([request respond raise]
(if (->> (:uri request)
(contains? ping-uris-set))
(respond (ping-response))
(handler request respond raise)))))))