From 7710ffcbf15496f9d04599c6391feab69f2d1b93 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 2 Feb 2022 15:31:54 +0100 Subject: [PATCH] :bug: Fix issue on 400 error handler. --- backend/src/app/http/errors.clj | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/src/app/http/errors.clj b/backend/src/app/http/errors.clj index 9e27ce9f1..b49df8e46 100644 --- a/backend/src/app/http/errors.clj +++ b/backend/src/app/http/errors.clj @@ -59,17 +59,25 @@ [err _] {:status 400 :body (ex-data err)}) +(defn- explain-spec-error-data + [data] + (when (and (::s/problems data) + (::s/value data) + (::s/spec data)) + (binding [s/*explain-out* expound/printer] + (with-out-str + (s/explain-out (update data ::s/problems #(take 10 %))))))) + + (defmethod handle-exception :validation [err _] (let [data (ex-data err) - explain (binding [s/*explain-out* expound/printer] - (with-out-str - (s/explain-out (update data ::s/problems #(take 10 %)))))] + explain (explain-spec-error-data data)] {:status 400 :body (-> data (dissoc ::s/problems) (dissoc ::s/value) - (assoc :explain explain))})) + (cond-> explain (assoc :explain explain)))})) (defmethod handle-exception :assertion [error request]