Improve error reporting.

This commit is contained in:
Andrey Antukh 2021-12-30 19:39:32 +01:00
parent d24d45f4cb
commit 9f0e156916
7 changed files with 107 additions and 144 deletions

View file

@ -11,6 +11,7 @@
[app.common.spec :as us]
[app.common.transit :as t]
[app.common.uuid :as uuid]
[clojure.pprint :as ppr]
[app.config :as cf]
[app.db :as db]
[app.util.template :as tmpl]
@ -99,7 +100,6 @@
(ex/raise :type :validation :code :invalid-arguments))))
(defn retrieve-error
[{:keys [pool]} request]
(letfn [(parse-id [request]
@ -107,14 +107,23 @@
id (us/uuid-conformer id)]
(when (uuid? id)
id)))
(retrieve-report [id]
(ex/ignoring
(when-let [{:keys [content] :as row} (db/get-by-id pool :server-error-report id)]
(assoc row :content (db/decode-transit-pgobject content)))))
(some-> (db/get-by-id pool :server-error-report id) :content db/decode-transit-pgobject)))
(render-template [{:keys [content] :as report}]
(some-> (io/resource "error-report.tmpl")
(tmpl/render content)))]
(render-template [report]
(binding [ppr/*print-right-margin* 300]
(let [context (dissoc report :trace :cause :params :data :spec-prob :spec-problems)
params {:context (with-out-str (ppr/pprint context))
:data (:data report)
:trace (or (:cause report)
(:trace report)
(some-> report :error :trace))
:params (:params report)}]
(-> (io/resource "error-report.tmpl")
(tmpl/render params)))))
]
(when-not (authorized? pool request)
(ex/raise :type :authentication

View file

@ -30,14 +30,13 @@
:hint (or (:hint data) (ex-message error))
:params (l/stringify-data (:params request))
:spec-problems (some-> data ::s/problems)
:data (some-> data (dissoc ::s/problems))
:ip-addr (parse-client-ip request)
:profile-id (:profile-id request)}
(let [headers (:headers request)]
{:user-agent (get headers "user-agent")
:frontend-version (get headers "x-frontend-version" "unknown")})
(dissoc data ::s/problems))))
:frontend-version (get headers "x-frontend-version" "unknown")}))))
(defmulti handle-exception
(fn [err & _rest]
@ -56,8 +55,7 @@
(defmethod handle-exception :validation
[err _]
(let [edata (ex-data err)]
{:status 400
:body (dissoc edata ::s/problems)}))
{:status 400 :body edata}))
(defmethod handle-exception :assertion
[error request]

View file

@ -73,6 +73,7 @@
(if-let [{:keys [id profile-id] :as session} (retrieve-from-request cfg request)]
(do
(a/>!! (::events-ch cfg) id)
(l/set-context! {:profile-id profile-id})
(handler (assoc request :profile-id profile-id)))
(handler request))))

View file

@ -62,7 +62,7 @@
(let [event (parse-event event)
uri (cf/get :public-uri)]
(l/debug :hint "registering error on database" :id (:id event)
:uri (str uri "/dbg/error-by-id/" (:id event)))
:uri (str uri "/dbg/error/" (:id event)))
(persist-on-database! cfg event))
(catch Exception e
(l/warn :hint "unexpected exception on database error logger"