From 9334f935eb70d7a807e15d7d485156ed26f309ce Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 3 Aug 2023 16:10:41 +0200 Subject: [PATCH 1/3] :sparkles: Add better error reporting on response encoding middleware --- backend/resources/app/templates/error-report.v3.tmpl | 2 +- backend/src/app/http/middleware.clj | 9 ++++++--- backend/src/app/loggers/database.clj | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/resources/app/templates/error-report.v3.tmpl b/backend/resources/app/templates/error-report.v3.tmpl index 216c4d3eb..b36a97e49 100644 --- a/backend/resources/app/templates/error-report.v3.tmpl +++ b/backend/resources/app/templates/error-report.v3.tmpl @@ -71,7 +71,7 @@ penpot - error report v2 {{id}} {% if value %}
-
VALIDATION VALUE:
+
VALUE:
{{value}}
diff --git a/backend/src/app/http/middleware.clj b/backend/src/app/http/middleware.clj index e11a60d04..2e6161bcd 100644 --- a/backend/src/app/http/middleware.clj +++ b/backend/src/app/http/middleware.clj @@ -118,7 +118,9 @@ (t/write! tw data))) (catch java.io.IOException _) (catch Throwable cause - (l/error :hint "unexpected error on encoding response" :cause cause)) + (binding [l/*context* {:value data}] + (l/error :hint "unexpected error on encoding response" + :cause cause))) (finally (.close ^OutputStream output-stream)))))) @@ -131,8 +133,9 @@ (catch java.io.IOException _) (catch Throwable cause - (l/error :hint "unexpected error on encoding response" - :cause cause)) + (binding [l/*context* {:value data}] + (l/error :hint "unexpected error on encoding response" + :cause cause))) (finally (.close ^OutputStream output-stream)))))) diff --git a/backend/src/app/loggers/database.clj b/backend/src/app/loggers/database.clj index a29578374..093175ada 100644 --- a/backend/src/app/loggers/database.clj +++ b/backend/src/app/loggers/database.clj @@ -58,6 +58,9 @@ (when-let [params (:request/params context)] {:params (pp/pprint-str params :width 200)}) + (when-let [value (:value context)] + {:value (pp/pprint-str value :width 200 :length 50 :level 10)}) + (when-let [data (some-> data (dissoc ::s/problems ::s/value ::s/spec ::sm/explain :hint))] {:data (pp/pprint-str data :width 200)}) From 54bb89b2bb941674b437ee80c39f49ba4a4e6872 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 3 Aug 2023 16:23:01 +0200 Subject: [PATCH 2/3] :arrow_up: Upgrade yetti to v9.16 (fixes exception unwrapping) --- backend/deps.edn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/deps.edn b/backend/deps.edn index 0b4e5180a..5bf32ab95 100644 --- a/backend/deps.edn +++ b/backend/deps.edn @@ -21,8 +21,8 @@ java-http-clj/java-http-clj {:mvn/version "0.4.3"} funcool/yetti - {:git/tag "v9.15" - :git/sha "aa9b967" + {:git/tag "v9.16" + :git/sha "7df3e08" :git/url "https://github.com/funcool/yetti.git" :exclusions [org.slf4j/slf4j-api]} From 0527c55398c72e480cec91bbd916bc6032cf4981 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 3 Aug 2023 16:28:50 +0200 Subject: [PATCH 3/3] :sparkles: Add better exception handling on json content type handling --- backend/src/app/http/middleware.clj | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/src/app/http/middleware.clj b/backend/src/app/http/middleware.clj index 2e6161bcd..f71f9da95 100644 --- a/backend/src/app/http/middleware.clj +++ b/backend/src/app/http/middleware.clj @@ -22,9 +22,10 @@ (:import com.fasterxml.jackson.core.JsonParseException com.fasterxml.jackson.core.io.JsonEOFException + com.fasterxml.jackson.databind.exc.MismatchedInputException io.undertow.server.RequestTooBigException - java.io.OutputStream - java.io.InputStream)) + java.io.InputStream + java.io.OutputStream)) (set! *warn-on-reflection* true) @@ -78,11 +79,13 @@ (or (instance? JsonEOFException cause) - (instance? JsonParseException cause)) + (instance? JsonParseException cause) + (instance? MismatchedInputException cause)) (raise (ex/error :type :validation :code :malformed-json :hint (ex-message cause) :cause cause)) + :else (raise cause)))]