mirror of
https://github.com/metosin/reitit.git
synced 2025-12-21 18:11:12 +00:00
Add metosin/ring-http-response support to exception middleware.
This commit is contained in:
parent
0faf2af876
commit
5aac69f563
3 changed files with 17 additions and 2 deletions
|
|
@ -2,7 +2,8 @@
|
|||
(:require [reitit.coercion :as coercion]
|
||||
[reitit.ring :as ring]
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.string :as str])
|
||||
[clojure.string :as str]
|
||||
[ring.util.http-response :as http-response])
|
||||
(:import (java.time Instant)
|
||||
(java.io PrintWriter)))
|
||||
|
||||
|
|
@ -98,6 +99,7 @@
|
|||
(def default-handlers
|
||||
{::default default-handler
|
||||
::ring/response http-response-handler
|
||||
::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)})
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
[metosin/reitit-frontend "0.3.10"]
|
||||
[metosin/reitit-sieppari "0.3.10"]
|
||||
[metosin/reitit-pedestal "0.3.10"]
|
||||
[metosin/ring-http-response "0.9.1"]
|
||||
[metosin/ring-swagger-ui "2.2.10"]
|
||||
[metosin/spec-tools "0.10.0"]
|
||||
[metosin/schema-tools "0.12.0"]
|
||||
|
|
@ -90,6 +91,7 @@
|
|||
[ring "1.7.1"]
|
||||
[ikitommi/immutant-web "3.0.0-alpha1"]
|
||||
[metosin/ring-swagger-ui "2.2.10"]
|
||||
[metosin/ring-http-response "0.9.1"]
|
||||
[metosin/muuntaja]
|
||||
[metosin/sieppari]
|
||||
[metosin/jsonista]
|
||||
|
|
|
|||
|
|
@ -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