0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-11 23:31:21 -05:00

🎉 Add the ability to execute code on the end of http request.

Mainly for register metrics once the main transaction is commited.
This commit is contained in:
Andrey Antukh 2021-02-22 12:48:21 +01:00 committed by Andrés Moya
parent c79036aa65
commit 995017df5a

View file

@ -25,6 +25,11 @@
[_]
(ex/raise :type :not-found))
(defn- run-hook
[hook-fn response]
(ex/ignoring (hook-fn))
response)
(defn- rpc-query-handler
[methods {:keys [profile-id] :as request}]
(let [type (keyword (get-in request [:path-params :type]))
@ -50,7 +55,11 @@
result ((get methods type default-handler) data)
mdata (meta result)]
(cond->> {:status 200 :body result}
(fn? (:transform-response mdata)) ((:transform-response mdata) request))))
(fn? (:transform-response mdata))
((:transform-response mdata) request)
(fn? (:before-complete mdata))
(run-hook (:before-complete mdata)))))
(defn- wrap-with-metrics
[cfg f mdata]