diff --git a/modules/reitit-middleware/src/reitit/ring/middleware/exception.clj b/modules/reitit-middleware/src/reitit/ring/middleware/exception.clj index 62a9a03c..92bbdec5 100644 --- a/modules/reitit-middleware/src/reitit/ring/middleware/exception.clj +++ b/modules/reitit-middleware/src/reitit/ring/middleware/exception.clj @@ -98,6 +98,7 @@ (def default-handlers {::default default-handler ::ring/response http-response-handler + :ring.util.http-response/response http-response-handler :muuntaja/decode request-parsing-handler ::coercion/request-coercion (create-coercion-handler 400) ::coercion/response-coercion (create-coercion-handler 500)}) diff --git a/project.clj b/project.clj index 90125dd9..e1e1e975 100644 --- a/project.clj +++ b/project.clj @@ -89,6 +89,7 @@ [ring "1.7.1"] [ikitommi/immutant-web "3.0.0-alpha1"] + [metosin/ring-http-response "0.9.1"] [metosin/ring-swagger-ui "2.2.10"] [metosin/muuntaja] [metosin/sieppari] diff --git a/test/clj/reitit/ring/middleware/exception_test.clj b/test/clj/reitit/ring/middleware/exception_test.clj index 8414a020..5ef64770 100644 --- a/test/clj/reitit/ring/middleware/exception_test.clj +++ b/test/clj/reitit/ring/middleware/exception_test.clj @@ -6,7 +6,8 @@ [clojure.spec.alpha :as s] [reitit.coercion.spec] [reitit.ring.coercion] - [muuntaja.core :as m]) + [muuntaja.core :as m] + [ring.util.http-response :as http-response]) (:import (java.sql SQLException SQLWarning))) (derive ::kikka ::kukka) @@ -20,6 +21,9 @@ (ring/router [["/defaults" {:handler f}] + ["/http-response" + {:handler (fn [req] + (http-response/unauthorized! "Unauthorized"))}] ["/coercion" {:middleware [reitit.ring.coercion/coerce-request-middleware reitit.ring.coercion/coerce-response-middleware] @@ -56,6 +60,13 @@ app (create (fn [_] (throw (ex-info "fail" {:type ::ring/response, :response response}))))] (is (= response (app {:request-method :get, :uri "/defaults"}))))) + (testing "::ring.util.http-response/response" + (let [response {:status 401 :body "Unauthorized" :headers {}} + app (create (fn [_] (throw (ex-info "Unauthorized!" {:type ::http-response/response + :response response}))))] + (is (= response (app {:request-method :post, :uri "/http-response"}))))) + + (testing ":muuntaja/decode" (let [app (create (fn [_] (m/decode m/instance "application/json" "{:so \"invalid\"}")))] (is (= {:body "Malformed \"application/json\" request."