0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 23:18:48 -05:00

🐛 Fix error reporting regression

This commit is contained in:
Andrey Antukh 2024-07-25 15:46:08 +02:00
parent 5ed49995f0
commit af389fe63a
3 changed files with 14 additions and 17 deletions

View file

@ -150,8 +150,8 @@
[["" {:middleware [[mw/server-timing] [["" {:middleware [[mw/server-timing]
[mw/params] [mw/params]
[mw/format-response] [mw/format-response]
[mw/errors errors/handle]
[mw/parse-request] [mw/parse-request]
[mw/errors errors/handle]
[session/soft-auth cfg] [session/soft-auth cfg]
[actoken/soft-auth cfg] [actoken/soft-auth cfg]
[mw/restrict-methods]]} [mw/restrict-methods]]}

View file

@ -14,32 +14,28 @@
[app.http :as-alias http] [app.http :as-alias http]
[app.http.access-token :as-alias actoken] [app.http.access-token :as-alias actoken]
[app.http.session :as-alias session] [app.http.session :as-alias session]
[app.util.inet :as inet]
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[cuerdas.core :as str]
[ring.request :as rreq] [ring.request :as rreq]
[ring.response :as rres])) [ring.response :as rres]))
(defn- parse-client-ip
[request]
(or (some-> (rreq/get-header request "x-forwarded-for") (str/split ",") first)
(rreq/get-header request "x-real-ip")
(rreq/remote-addr request)))
(defn request->context (defn request->context
"Extracts error report relevant context data from request." "Extracts error report relevant context data from request."
[request] [request]
(let [claims (-> {} (let [claims (-> {}
(into (::session/token-claims request)) (into (::session/token-claims request))
(into (::actoken/token-claims request)))] (into (::actoken/token-claims request)))]
{:request/path (:path request) {:request/path (:path request)
:request/method (:method request) :request/method (:method request)
:request/params (:params request) :request/params (:params request)
:request/user-agent (rreq/get-header request "user-agent") :request/user-agent (rreq/get-header request "user-agent")
:request/ip-addr (parse-client-ip request) :request/ip-addr (inet/parse-request request)
:request/profile-id (:uid claims) :request/profile-id (:uid claims)
:version/frontend (or (rreq/get-header request "x-frontend-version") "unknown") :version/frontend (or (rreq/get-header request "x-frontend-version") "unknown")
:version/backend (:full cf/version)})) :version/backend (:full cf/version)}))
(defmulti handle-error (defmulti handle-error
(fn [cause _ _] (fn [cause _ _]
(-> cause ex-data :type))) (-> cause ex-data :type)))

View file

@ -10,6 +10,7 @@
[app.common.logging :as l] [app.common.logging :as l]
[app.common.transit :as t] [app.common.transit :as t]
[app.config :as cf] [app.config :as cf]
[app.http.errors :as errors]
[clojure.data.json :as json] [clojure.data.json :as json]
[cuerdas.core :as str] [cuerdas.core :as str]
[ring.request :as rreq] [ring.request :as rreq]
@ -70,12 +71,12 @@
:else :else
request))) request)))
(handle-error [cause] (handle-error [cause request]
(cond (cond
(instance? RuntimeException cause) (instance? RuntimeException cause)
(if-let [cause (ex-cause cause)] (if-let [cause (ex-cause cause)]
(handle-error cause) (handle-error cause request)
(throw cause)) (errors/handle cause request))
(instance? RequestTooBigException cause) (instance? RequestTooBigException cause)
(ex/raise :type :validation (ex/raise :type :validation
@ -89,14 +90,14 @@
:cause cause) :cause cause)
:else :else
(throw cause)))] (errors/handle cause request)))]
(fn [request] (fn [request]
(if (= (rreq/method request) :post) (if (= (rreq/method request) :post)
(let [request (ex/try! (process-request request))] (try
(if (ex/exception? request) (-> request process-request handler)
(handle-error request) (catch Throwable cause
(handler request))) (handle-error cause request)))
(handler request))))) (handler request)))))
(def parse-request (def parse-request