mirror of
https://github.com/penpot/penpot.git
synced 2025-05-14 15:46:38 +02:00
✨ Improve error reporting
This commit is contained in:
parent
701a98fab6
commit
ca02999ae9
3 changed files with 54 additions and 7 deletions
|
@ -15,6 +15,8 @@
|
||||||
[yetti.request :as yrq]
|
[yetti.request :as yrq]
|
||||||
[yetti.response :as yrs]))
|
[yetti.response :as yrs]))
|
||||||
|
|
||||||
|
(def ^:dynamic *context* {})
|
||||||
|
|
||||||
(defn- parse-client-ip
|
(defn- parse-client-ip
|
||||||
[request]
|
[request]
|
||||||
(or (some-> (yrq/get-header request "x-forwarded-for") (str/split ",") first)
|
(or (some-> (yrq/get-header request "x-forwarded-for") (str/split ",") first)
|
||||||
|
@ -24,6 +26,7 @@
|
||||||
(defn get-context
|
(defn get-context
|
||||||
[request]
|
[request]
|
||||||
(merge
|
(merge
|
||||||
|
*context*
|
||||||
{:path (:path request)
|
{:path (:path request)
|
||||||
:method (:method request)
|
:method (:method request)
|
||||||
:params (:params request)
|
:params (:params request)
|
||||||
|
@ -137,9 +140,21 @@
|
||||||
:code :unhandled
|
:code :unhandled
|
||||||
:hint (ex-message error)
|
:hint (ex-message error)
|
||||||
:data edata})))))
|
:data edata})))))
|
||||||
|
|
||||||
(defn handle
|
(defn handle
|
||||||
[error request]
|
[cause request]
|
||||||
(if (or (instance? java.util.concurrent.CompletionException error)
|
|
||||||
(instance? java.util.concurrent.ExecutionException error))
|
(cond
|
||||||
(handle-exception (.getCause ^Throwable error) request)
|
(or (instance? java.util.concurrent.CompletionException cause)
|
||||||
(handle-exception error request)))
|
(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)))
|
||||||
|
|
|
@ -59,7 +59,9 @@
|
||||||
(-> (method data)
|
(-> (method data)
|
||||||
(p/then handle-response)
|
(p/then handle-response)
|
||||||
(p/then respond)
|
(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
|
(defn- rpc-mutation-handler
|
||||||
"Ring handler that dispatches mutation requests and convert between
|
"Ring handler that dispatches mutation requests and convert between
|
||||||
|
@ -81,7 +83,9 @@
|
||||||
(-> (method data)
|
(-> (method data)
|
||||||
(p/then handle-response)
|
(p/then handle-response)
|
||||||
(p/then respond)
|
(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
|
(defn- wrap-metrics
|
||||||
"Wrap service method with metrics measurement."
|
"Wrap service method with metrics measurement."
|
||||||
|
|
|
@ -57,3 +57,31 @@
|
||||||
(defn exception?
|
(defn exception?
|
||||||
[v]
|
[v]
|
||||||
(instance? #?(:clj java.lang.Throwable :cljs js/Error) 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))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue