From e6e71e9278778f3aabd99194925cf1b25e2d1968 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 1 Apr 2025 20:24:07 +0200 Subject: [PATCH] :sparkles: Add minor enhacement for error reporting --- backend/src/app/http/errors.clj | 7 ++++--- backend/src/app/loggers/database.clj | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/src/app/http/errors.clj b/backend/src/app/http/errors.clj index cd32928017..eaeb9eef7e 100644 --- a/backend/src/app/http/errors.clj +++ b/backend/src/app/http/errors.clj @@ -61,7 +61,8 @@ ::yres/body data} (binding [l/*context* (request->context request)] - (l/err :hint "restriction error" :data data) + (l/err :hint "restriction error" + :cause err) {::yres/status 400 ::yres/body data})))) @@ -101,7 +102,7 @@ (= code :invalid-image) (binding [l/*context* (request->context request)] (let [cause (or parent-cause err)] - (l/warn :hint "unexpected error on processing image" :cause cause) + (l/warn :hint "image process error" :cause cause) {::yres/status 400 ::yres/body data})) :else @@ -176,7 +177,7 @@ (let [state (.getSQLState ^java.sql.SQLException error) cause (or parent-cause error)] (binding [l/*context* (request->context request)] - (l/error :hint "PSQL error" + (l/error :hint "postgresql error" :cause cause) (cond (= state "57014") diff --git a/backend/src/app/loggers/database.clj b/backend/src/app/loggers/database.clj index 41584eddca..196845a967 100644 --- a/backend/src/app/loggers/database.clj +++ b/backend/src/app/loggers/database.clj @@ -53,11 +53,16 @@ (assoc :logger/name logger) (assoc :logger/level level) (dissoc :request/params :value :params :data))] + (merge {:context (-> (into (sorted-map) ctx) (pp/pprint-str :length 50)) :props (pp/pprint-str props :length 50) - :hint (or (ex-message cause) @message) + :hint (or (when-let [message (ex-message cause)] + (if-let [props-hint (:hint props)] + (str props-hint ": " message) + message)) + @message) :trace (or (::trace record) (some-> cause (ex/format-throwable :data? false :explain? false :header? false :summary? false)))}