0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-18 18:51:29 -05:00

Improve error reporting

This commit is contained in:
Andrey Antukh 2022-04-01 17:16:59 +02:00 committed by Andrés Moya
parent 701a98fab6
commit ca02999ae9
3 changed files with 54 additions and 7 deletions

View file

@ -15,6 +15,8 @@
[yetti.request :as yrq]
[yetti.response :as yrs]))
(def ^:dynamic *context* {})
(defn- parse-client-ip
[request]
(or (some-> (yrq/get-header request "x-forwarded-for") (str/split ",") first)
@ -24,6 +26,7 @@
(defn get-context
[request]
(merge
*context*
{:path (:path request)
:method (:method request)
:params (:params request)
@ -137,9 +140,21 @@
:code :unhandled
:hint (ex-message error)
:data edata})))))
(defn handle
[error request]
(if (or (instance? java.util.concurrent.CompletionException error)
(instance? java.util.concurrent.ExecutionException error))
(handle-exception (.getCause ^Throwable error) request)
(handle-exception error request)))
[cause request]
(cond
(or (instance? java.util.concurrent.CompletionException cause)
(instance? java.util.concurrent.ExecutionException cause))
(handle-exception (.getCause ^Throwable cause) request)
(ex/wrapped? cause)
(let [context (meta cause)
cause (deref cause)]
(binding [*context* context]
(handle-exception cause request)))
:else
(handle-exception cause request)))

View file

@ -59,7 +59,9 @@
(-> (method data)
(p/then handle-response)
(p/then respond)
(p/catch raise)))))
(p/catch (fn [cause]
(let [context {:profile-id profile-id}]
(raise (ex/wrap-with-context cause context)))))))))
(defn- rpc-mutation-handler
"Ring handler that dispatches mutation requests and convert between
@ -81,7 +83,9 @@
(-> (method data)
(p/then handle-response)
(p/then respond)
(p/catch raise)))))
(p/catch (fn [cause]
(let [context {:profile-id profile-id}]
(raise (ex/wrap-with-context cause context)))))))))
(defn- wrap-metrics
"Wrap service method with metrics measurement."

View file

@ -57,3 +57,31 @@
(defn exception?
[v]
(instance? #?(:clj java.lang.Throwable :cljs js/Error) v))
#?(:cljs
(deftype WrappedException [cause meta]
cljs.core/IMeta
(-meta [_] meta)
cljs.core/IDeref
(-deref [_] cause))
:clj
(deftype WrappedException [cause meta]
clojure.lang.IMeta
(meta [_] meta)
clojure.lang.IDeref
(deref [_] cause)))
(ns-unmap 'app.common.exceptions '->WrappedException)
(ns-unmap 'app.common.exceptions 'map->WrappedException)
(defn wrapped?
[o]
(instance? WrappedException o))
(defn wrap-with-context
[cause context]
(WrappedException. cause context))