mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 18:06:38 +02:00
⚡ Improve performance on error formating and reporting
This commit is contained in:
parent
c64e14859c
commit
2295d085d3
9 changed files with 56 additions and 69 deletions
|
@ -9,7 +9,7 @@
|
|||
(:require
|
||||
[app.common.exceptions :as ex]
|
||||
[app.common.logging :as l]
|
||||
[app.common.schema :as sm]
|
||||
[app.common.schema :as-alias sm]
|
||||
[app.config :as cf]
|
||||
[app.http :as-alias http]
|
||||
[app.http.access-token :as-alias actoken]
|
||||
|
@ -79,29 +79,15 @@
|
|||
[err request parent-cause]
|
||||
(let [{:keys [code] :as data} (ex-data err)]
|
||||
(cond
|
||||
(= code :spec-validation)
|
||||
(or (= code :spec-validation)
|
||||
(= code :params-validation)
|
||||
(= code :data-validation))
|
||||
(let [explain (ex/explain data)]
|
||||
{::rres/status 400
|
||||
::rres/body (-> data
|
||||
(dissoc ::s/problems ::s/value ::s/spec)
|
||||
(dissoc ::s/problems ::s/value ::s/spec ::sm/explain)
|
||||
(cond-> explain (assoc :explain explain)))})
|
||||
|
||||
(= code :params-validation)
|
||||
(let [explain (::sm/explain data)
|
||||
explain (sm/humanize-data explain)]
|
||||
{::rres/status 400
|
||||
::rres/body (-> data
|
||||
(dissoc ::sm/explain)
|
||||
(assoc :explain explain))})
|
||||
|
||||
(= code :data-validation)
|
||||
(let [explain (::sm/explain data)
|
||||
explain (sm/humanize-data explain)]
|
||||
{::rres/status 400
|
||||
::rres/body (-> data
|
||||
(dissoc ::sm/explain)
|
||||
(assoc :explain explain))})
|
||||
|
||||
(= code :request-body-too-large)
|
||||
{::rres/status 413 ::rres/body data}
|
||||
|
||||
|
|
|
@ -56,22 +56,22 @@
|
|||
(dissoc :request/params :value :params :data))]
|
||||
(merge
|
||||
{:context (-> (into (sorted-map) ctx)
|
||||
(pp/pprint-str :width 200 :length 50 :level 10))
|
||||
:props (pp/pprint-str props :width 200 :length 50)
|
||||
(pp/pprint-str :length 50))
|
||||
:props (pp/pprint-str props :length 50)
|
||||
:hint (or (ex-message cause) @message)
|
||||
:trace (or (::trace record)
|
||||
(ex/format-throwable cause :data? false :explain? false :header? false :summary? false))}
|
||||
|
||||
(when-let [params (or (:request/params context) (:params context))]
|
||||
{:params (pp/pprint-str params :width 200 :length 50 :level 10)})
|
||||
{:params (pp/pprint-str params :length 30 :level 12)})
|
||||
|
||||
(when-let [value (:value context)]
|
||||
{:value (pp/pprint-str value :width 200 :length 50 :level 10)})
|
||||
{:value (pp/pprint-str value :length 30 :level 12)})
|
||||
|
||||
(when-let [data (some-> data (dissoc ::s/problems ::s/value ::s/spec ::sm/explain :hint))]
|
||||
{:data (pp/pprint-str data :width 200)})
|
||||
{:data (pp/pprint-str data :length 30 :level 12)})
|
||||
|
||||
(when-let [explain (ex/explain data {:level 8 :length 20})]
|
||||
(when-let [explain (ex/explain data :length 30 :level 12)]
|
||||
{:explain explain})))))
|
||||
|
||||
(defn error-record?
|
||||
|
@ -96,11 +96,11 @@
|
|||
|
||||
(defmethod ig/init-key ::reporter
|
||||
[_ cfg]
|
||||
(let [input (sp/chan :buf (sp/sliding-buffer 32)
|
||||
(let [input (sp/chan :buf (sp/sliding-buffer 64)
|
||||
:xf (filter error-record?))]
|
||||
(add-watch l/log-record ::reporter #(sp/put! input %4))
|
||||
|
||||
(px/thread {:name "penpot/database-reporter" :virtual true}
|
||||
(px/thread {:name "penpot/database-reporter"}
|
||||
(l/info :hint "initializing database error persistence")
|
||||
(try
|
||||
(loop []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue