From ea218839e4df3e3c96d1c1578a0317a3e868de7f Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 17 Nov 2021 11:10:28 +0100 Subject: [PATCH] :sparkles: Minor change on error pruning mechanism. --- backend/src/app/http/errors.clj | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/src/app/http/errors.clj b/backend/src/app/http/errors.clj index ab8f7e1d2..ec489054e 100644 --- a/backend/src/app/http/errors.clj +++ b/backend/src/app/http/errors.clj @@ -20,11 +20,19 @@ (get headers "x-real-ip") (get request :remote-addr))) + +(defn- simple-prune + ([s] (simple-prune s (* 1024 1024))) + ([s max-length] + (if (> (count s) max-length) + (str (subs s 0 max-length) " [...]") + s))) + (defn- stringify-data [data] (binding [clojure.pprint/*print-right-margin* 200] (let [result (with-out-str (clojure.pprint/pprint data))] - (str/prune result (* 1024 1024) "[...]")))) + (simple-prune result (* 1024 1024))))) (defn get-error-context [request error]