-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.clj
32 lines (29 loc) · 1014 Bytes
/
handler.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(ns corbihttp.interceptor.handler
(:require [corbihttp.params :as params]
[exoscale.coax :as c]
[exoscale.ex :as ex]))
(defn assert-spec-valid
[spec params]
(if spec
(ex/assert-spec-valid spec params)
params))
(defn main-handler-enter
[{:keys [request] :as ctx}
{:keys [dispatch-map
handler-component]}]
(let [req-handler (:handler ctx)
{:keys [handler-fn spec]} (get dispatch-map req-handler)]
(->> (handler-fn handler-component
(-> request
params/merge-params
(update :all-params
#(->> (c/coerce spec (or % {}))
(assert-spec-valid spec)))))
(assoc ctx :response))))
(defn main-handler
"This interceptor expects that the handler is in the :handler key."
[params]
{:name ::main-handler
:enter (fn [ctx]
(main-handler-enter ctx
params))})