mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +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
|
||||
{::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)})
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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."
|
||||
|
|
|
|||
Loading…
Reference in a new issue