mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
Add route-data to coerce-request compile failure
This commit is contained in:
parent
3a6985eb71
commit
62caa9399d
2 changed files with 21 additions and 12 deletions
|
|
@ -164,7 +164,7 @@
|
|||
"A router :compile implementation which reads the `:parameters`
|
||||
and `:coercion` data to create compiled coercers into Match under
|
||||
`:result. A pre-requisite to use [[coerce!]]."
|
||||
[[_ {:keys [parameters coercion]}] opts]
|
||||
[[_ {:keys [parameters coercion] :as match}] opts]
|
||||
(if (and parameters coercion)
|
||||
(request-coercers coercion parameters opts)))
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
and :parameters from route data, otherwise does not mount."
|
||||
{:name ::coerce-request
|
||||
:spec ::rs/parameters
|
||||
:compile (fn [{:keys [coercion parameters]} opts]
|
||||
:compile (fn [{:keys [coercion parameters] :as route-data} opts]
|
||||
(cond
|
||||
;; no coercion, skip
|
||||
(not coercion) nil
|
||||
|
|
@ -32,6 +32,7 @@
|
|||
(not parameters) {}
|
||||
;; mount
|
||||
:else
|
||||
(try
|
||||
(if-let [coercers (coercion/request-coercers coercion parameters opts)]
|
||||
(fn [handler]
|
||||
(fn
|
||||
|
|
@ -41,7 +42,15 @@
|
|||
([request respond raise]
|
||||
(let [coerced (coercion/coerce-request coercers request)]
|
||||
(handler (impl/fast-assoc request :parameters coerced) respond raise)))))
|
||||
{})))})
|
||||
{})
|
||||
(catch Exception e
|
||||
(throw (ex-info (str "Coerce-request-middleware failed: " (.getMessage e))
|
||||
;; TODO: Format error properly
|
||||
{:type :coerce-request-middleware-fail
|
||||
;; TODO: Add path?
|
||||
:data {:route-data (select-keys route-data [:parameters])
|
||||
:cause-data (ex-data e)}}
|
||||
e))))))})
|
||||
|
||||
(def coerce-response-middleware
|
||||
"Middleware for pluggable response coercion.
|
||||
|
|
|
|||
Loading…
Reference in a new issue