mirror of
https://github.com/penpot/penpot.git
synced 2025-06-14 08:01:41 +02:00
✨ Improve internal error reporting
This commit is contained in:
parent
80d719353c
commit
be0814cdac
1 changed files with 77 additions and 68 deletions
|
@ -202,9 +202,8 @@
|
||||||
cancel-text])
|
cancel-text])
|
||||||
[:button {:on-click on-click} button-text]]]]))
|
[:button {:on-click on-click} button-text]]]]))
|
||||||
|
|
||||||
(mf/defc request-access
|
(mf/defc request-access*
|
||||||
{::mf/props :obj}
|
[{:keys [file-id team-id is-default is-workspace]}]
|
||||||
[{:keys [file-id team-id is-default workspace?]}]
|
|
||||||
(let [profile (mf/deref refs/profile)
|
(let [profile (mf/deref refs/profile)
|
||||||
requested* (mf/use-state {:sent false :already-requested false})
|
requested* (mf/use-state {:sent false :already-requested false})
|
||||||
requested (deref requested*)
|
requested (deref requested*)
|
||||||
|
@ -227,11 +226,11 @@
|
||||||
|
|
||||||
on-request-access
|
on-request-access
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps file-id team-id workspace?)
|
(mf/deps file-id team-id is-workspace)
|
||||||
(fn []
|
(fn []
|
||||||
(let [params (if (some? file-id)
|
(let [params (if (some? file-id)
|
||||||
{:file-id file-id
|
{:file-id file-id
|
||||||
:is-viewer (not workspace?)}
|
:is-viewer (not is-workspace)}
|
||||||
{:team-id team-id})
|
{:team-id team-id})
|
||||||
mdata {:on-success on-success
|
mdata {:on-success on-success
|
||||||
:on-error on-error}]
|
:on-error on-error}]
|
||||||
|
@ -240,7 +239,7 @@
|
||||||
|
|
||||||
[:*
|
[:*
|
||||||
(if (some? file-id)
|
(if (some? file-id)
|
||||||
(if workspace?
|
(if is-workspace
|
||||||
[:div {:class (stl/css :workspace)}
|
[:div {:class (stl/css :workspace)}
|
||||||
[:div {:class (stl/css :workspace-left)}
|
[:div {:class (stl/css :workspace-left)}
|
||||||
i/logo-icon
|
i/logo-icon
|
||||||
|
@ -341,7 +340,7 @@
|
||||||
[:div {:class (stl/css :sign-info)}
|
[:div {:class (stl/css :sign-info)}
|
||||||
[:button {:on-click handle-retry} (tr "labels.retry")]]]))
|
[:button {:on-click handle-retry} (tr "labels.retry")]]]))
|
||||||
|
|
||||||
(mf/defc service-unavailable
|
(mf/defc service-unavailable*
|
||||||
[]
|
[]
|
||||||
(let [on-click (mf/use-fn #(st/emit! (rt/assign-exception nil)))]
|
(let [on-click (mf/use-fn #(st/emit! (rt/assign-exception nil)))]
|
||||||
[:> error-container* {}
|
[:> error-container* {}
|
||||||
|
@ -350,15 +349,15 @@
|
||||||
[:div {:class (stl/css :sign-info)}
|
[:div {:class (stl/css :sign-info)}
|
||||||
[:button {:on-click on-click} (tr "labels.retry")]]]))
|
[:button {:on-click on-click} (tr "labels.retry")]]]))
|
||||||
|
|
||||||
(defn generate-report
|
(defn- generate-report
|
||||||
[data]
|
[data]
|
||||||
(try
|
(try
|
||||||
(let [team-id (:current-team-id @st/state)
|
(let [team-id (:current-team-id @st/state)
|
||||||
profile-id (:profile-id @st/state)
|
profile-id (:profile-id @st/state)
|
||||||
|
|
||||||
trace (:app.main.errors/trace data)
|
trace (:app.main.errors/trace data)
|
||||||
instance (:app.main.errors/instance data)
|
instance (:app.main.errors/instance data)]
|
||||||
content (with-out-str
|
(with-out-str
|
||||||
(println "Hint: " (or (:hint data) (ex-message instance) "--"))
|
(println "Hint: " (or (:hint data) (ex-message instance) "--"))
|
||||||
(println "Prof ID:" (str (or profile-id "--")))
|
(println "Prof ID:" (str (or profile-id "--")))
|
||||||
(println "Team ID:" (str (or team-id "--")))
|
(println "Team ID:" (str (or team-id "--")))
|
||||||
|
@ -391,17 +390,14 @@
|
||||||
(println "Last events:")
|
(println "Last events:")
|
||||||
(pp/pprint @st/last-events {:length 200})
|
(pp/pprint @st/last-events {:length 200})
|
||||||
|
|
||||||
(println))]
|
(println)))
|
||||||
(wapi/create-blob content "text/plain"))
|
|
||||||
(catch :default cause
|
(catch :default cause
|
||||||
(.error js/console "error on generating report.txt" cause)
|
(.error js/console "error on generating report.txt" cause)
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
(mf/defc internal-error*
|
(mf/defc internal-error*
|
||||||
{::mf/props :obj}
|
[{:keys [on-reset report] :as props}]
|
||||||
[{:keys [data on-reset] :as props}]
|
|
||||||
(let [report-uri (mf/use-ref nil)
|
(let [report-uri (mf/use-ref nil)
|
||||||
report (mf/use-memo (mf/deps data) #(generate-report data))
|
|
||||||
on-reset (or on-reset #(st/emit! (rt/assign-exception nil)))
|
on-reset (or on-reset #(st/emit! (rt/assign-exception nil)))
|
||||||
|
|
||||||
on-download
|
on-download
|
||||||
|
@ -413,8 +409,8 @@
|
||||||
|
|
||||||
(mf/with-effect [report]
|
(mf/with-effect [report]
|
||||||
(when (some? report)
|
(when (some? report)
|
||||||
|
(let [report (wapi/create-blob report "text/plain")
|
||||||
(let [uri (wapi/create-uri report)]
|
uri (wapi/create-uri report)]
|
||||||
(mf/set-ref-val! report-uri uri)
|
(mf/set-ref-val! report-uri uri)
|
||||||
(fn []
|
(fn []
|
||||||
(wapi/revoke-uri uri)))))
|
(wapi/revoke-uri uri)))))
|
||||||
|
@ -455,6 +451,38 @@
|
||||||
(rx/of default)
|
(rx/of default)
|
||||||
(rx/throw cause)))))))
|
(rx/throw cause)))))))
|
||||||
|
|
||||||
|
(mf/defc exception-section*
|
||||||
|
{::mf/private true}
|
||||||
|
[{:keys [data route] :as props}]
|
||||||
|
(let [type (get data :type)
|
||||||
|
report (mf/with-memo [data]
|
||||||
|
(generate-report data))
|
||||||
|
props (mf/spread-props props {:report report})]
|
||||||
|
|
||||||
|
(mf/with-effect [data route report]
|
||||||
|
(let [params (:query-params route)
|
||||||
|
params (u/map->query-string params)]
|
||||||
|
(st/emit! (ptk/data-event ::ev/event
|
||||||
|
{::ev/name "exception-page"
|
||||||
|
:type (get data :type :unknown)
|
||||||
|
:hint (get data :hint)
|
||||||
|
:path (get route :path)
|
||||||
|
:report report
|
||||||
|
:params params}))))
|
||||||
|
(case type
|
||||||
|
:not-found
|
||||||
|
[:> not-found* {}]
|
||||||
|
|
||||||
|
:authentication
|
||||||
|
[:> not-found* {}]
|
||||||
|
|
||||||
|
:bad-gateway
|
||||||
|
[:> bad-gateway* props]
|
||||||
|
|
||||||
|
:service-unavailable
|
||||||
|
[:> service-unavailable*]
|
||||||
|
|
||||||
|
[:> internal-error* props])))
|
||||||
|
|
||||||
(mf/defc exception-page*
|
(mf/defc exception-page*
|
||||||
{::mf/props :obj}
|
{::mf/props :obj}
|
||||||
|
@ -477,42 +505,23 @@
|
||||||
|
|
||||||
request-access?
|
request-access?
|
||||||
(and
|
(and
|
||||||
(or (= (:type data) :not-found)
|
(or (= type :not-found)
|
||||||
(= (:type data) :authentication))
|
(= type :authentication))
|
||||||
(or workspace? dashboard? view?)
|
(or workspace? dashboard? view?)
|
||||||
(or (:file-id info)
|
(or (:file-id info)
|
||||||
(:team-id info)))]
|
(:team-id info)))]
|
||||||
|
|
||||||
(mf/with-effect [type path params]
|
|
||||||
(st/emit! (ptk/data-event ::ev/event
|
|
||||||
{::ev/name "exception-page"
|
|
||||||
:type type
|
|
||||||
:path path
|
|
||||||
:params (u/map->query-string params)})))
|
|
||||||
|
|
||||||
(mf/with-effect [params info]
|
(mf/with-effect [params info]
|
||||||
(when-not (:loaded info)
|
(when-not (:loaded info)
|
||||||
(->> (load-info params)
|
(->> (load-info params)
|
||||||
(rx/subs! (partial reset! info*)))))
|
(rx/subs! (partial reset! info*)
|
||||||
|
(partial reset! info* {:loaded true})))))
|
||||||
|
|
||||||
(when loaded?
|
(when loaded?
|
||||||
(if request-access?
|
(if request-access?
|
||||||
[:& request-access {:file-id (:file-id info)
|
[:> request-access* {:file-id (:file-id info)
|
||||||
:team-id (:team-id info)
|
:team-id (:team-id info)
|
||||||
:is-default (:team-default info)
|
:is-default (:team-default info)
|
||||||
:workspace? workspace?}]
|
:is-workspace workspace?}]
|
||||||
|
[:> exception-section* props]))))
|
||||||
|
|
||||||
(case (:type data)
|
|
||||||
:not-found
|
|
||||||
[:> not-found* {}]
|
|
||||||
|
|
||||||
:authentication
|
|
||||||
[:> not-found* {}]
|
|
||||||
|
|
||||||
:bad-gateway
|
|
||||||
[:> bad-gateway* props]
|
|
||||||
|
|
||||||
:service-unavailable
|
|
||||||
[:& service-unavailable]
|
|
||||||
|
|
||||||
[:> internal-error* props])))))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue