mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 00:41:12 +00:00
Merge pull request #342 from mgrbyte/master
Add metosin/ring-http-response support to exception middleware.
This commit is contained in:
commit
00eb3a5f99
3 changed files with 14 additions and 1 deletions
|
|
@ -98,6 +98,7 @@
|
||||||
(def default-handlers
|
(def default-handlers
|
||||||
{::default default-handler
|
{::default default-handler
|
||||||
::ring/response http-response-handler
|
::ring/response http-response-handler
|
||||||
|
:ring.util.http-response/response http-response-handler
|
||||||
:muuntaja/decode request-parsing-handler
|
:muuntaja/decode request-parsing-handler
|
||||||
::coercion/request-coercion (create-coercion-handler 400)
|
::coercion/request-coercion (create-coercion-handler 400)
|
||||||
::coercion/response-coercion (create-coercion-handler 500)})
|
::coercion/response-coercion (create-coercion-handler 500)})
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@
|
||||||
|
|
||||||
[ring "1.7.1"]
|
[ring "1.7.1"]
|
||||||
[ikitommi/immutant-web "3.0.0-alpha1"]
|
[ikitommi/immutant-web "3.0.0-alpha1"]
|
||||||
|
[metosin/ring-http-response "0.9.1"]
|
||||||
[metosin/ring-swagger-ui "2.2.10"]
|
[metosin/ring-swagger-ui "2.2.10"]
|
||||||
[metosin/muuntaja]
|
[metosin/muuntaja]
|
||||||
[metosin/sieppari]
|
[metosin/sieppari]
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[reitit.coercion.spec]
|
[reitit.coercion.spec]
|
||||||
[reitit.ring.coercion]
|
[reitit.ring.coercion]
|
||||||
[muuntaja.core :as m])
|
[muuntaja.core :as m]
|
||||||
|
[ring.util.http-response :as http-response])
|
||||||
(:import (java.sql SQLException SQLWarning)))
|
(:import (java.sql SQLException SQLWarning)))
|
||||||
|
|
||||||
(derive ::kikka ::kukka)
|
(derive ::kikka ::kukka)
|
||||||
|
|
@ -20,6 +21,9 @@
|
||||||
(ring/router
|
(ring/router
|
||||||
[["/defaults"
|
[["/defaults"
|
||||||
{:handler f}]
|
{:handler f}]
|
||||||
|
["/http-response"
|
||||||
|
{:handler (fn [req]
|
||||||
|
(http-response/unauthorized! "Unauthorized"))}]
|
||||||
["/coercion"
|
["/coercion"
|
||||||
{:middleware [reitit.ring.coercion/coerce-request-middleware
|
{:middleware [reitit.ring.coercion/coerce-request-middleware
|
||||||
reitit.ring.coercion/coerce-response-middleware]
|
reitit.ring.coercion/coerce-response-middleware]
|
||||||
|
|
@ -56,6 +60,13 @@
|
||||||
app (create (fn [_] (throw (ex-info "fail" {:type ::ring/response, :response response}))))]
|
app (create (fn [_] (throw (ex-info "fail" {:type ::ring/response, :response response}))))]
|
||||||
(is (= response (app {:request-method :get, :uri "/defaults"})))))
|
(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"
|
(testing ":muuntaja/decode"
|
||||||
(let [app (create (fn [_] (m/decode m/instance "application/json" "{:so \"invalid\"}")))]
|
(let [app (create (fn [_] (m/decode m/instance "application/json" "{:so \"invalid\"}")))]
|
||||||
(is (= {:body "Malformed \"application/json\" request."
|
(is (= {:body "Malformed \"application/json\" request."
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue