From 4ee1f9cf2cb617f799e348c87dba92351a6e7c30 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 22 Jan 2021 15:23:21 +0100 Subject: [PATCH] :sparkles: Minor improvements on error handling on frontend. --- backend/src/app/http/auth.clj | 2 +- frontend/resources/locales.json | 14 +++++++++++++- frontend/src/app/main/data/messages.cljs | 2 -- frontend/src/app/main/ui.cljs | 11 +++-------- frontend/src/app/main/ui/static.cljs | 9 +++------ 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/backend/src/app/http/auth.clj b/backend/src/app/http/auth.clj index 4c65c675b..4dec0d3b4 100644 --- a/backend/src/app/http/auth.clj +++ b/backend/src/app/http/auth.clj @@ -26,6 +26,6 @@ (defn logout-handler [{:keys [session] :as cfg} request] (session/delete! cfg request) - {:status 200 + {:status 204 :cookies (session/cookies session {:value "" :max-age -1}) :body ""}) diff --git a/frontend/resources/locales.json b/frontend/resources/locales.json index 7f2466e86..55ecd6c2a 100644 --- a/frontend/resources/locales.json +++ b/frontend/resources/locales.json @@ -1496,6 +1496,18 @@ "es" : "Ocultar comentarios resueltos" } }, + "labels.internal-error.desc-message" : { + "used-in" : [ "src/app/main/ui/static.cljs:92" ], + "translations" : { + "en" : "Something bad happended. Please retry the operation and if the problem persists, contact with support." + } + }, + "labels.internal-error.main-message" : { + "used-in" : [ "src/app/main/ui/static.cljs:91" ], + "translations" : { + "en" : "Internal Error" + } + }, "labels.language" : { "used-in" : [ "src/app/main/ui/settings/options.cljs:54" ], "translations" : { @@ -1652,7 +1664,7 @@ } }, "labels.retry" : { - "used-in" : [ "src/app/main/ui/static.cljs:62", "src/app/main/ui/static.cljs:79" ], + "used-in" : [ "src/app/main/ui/static.cljs:62", "src/app/main/ui/static.cljs:79", "src/app/main/ui/static.cljs:96" ], "translations" : { "en" : "Retry" } diff --git a/frontend/src/app/main/data/messages.cljs b/frontend/src/app/main/data/messages.cljs index 107b9e17f..ac8bf9ec9 100644 --- a/frontend/src/app/main/data/messages.cljs +++ b/frontend/src/app/main/data/messages.cljs @@ -131,8 +131,6 @@ (defn assign-exception [{:keys [type] :as error}] - (us/assert (s/nilable map?) error) - (us/assert (s/nilable ::us/keyword) type) (ptk/reify ::assign-exception ptk/UpdateEvent (update [_ state] diff --git a/frontend/src/app/main/ui.cljs b/frontend/src/app/main/ui.cljs index d2e394b5e..653024898 100644 --- a/frontend/src/app/main/ui.cljs +++ b/frontend/src/app/main/ui.cljs @@ -101,7 +101,7 @@ (mf/defc on-main-error [{:keys [error] :as props}] (let [data (ex-data error)] - (ptk/handle-error error) + (mf/use-effect #(ptk/handle-error error)) [:span "Internal application errror"])) (mf/defc main-page @@ -285,22 +285,17 @@ (ptk/handle-error (ex-data error)) (do (ts/schedule - (st/emitf (dm/show - {:content "Something wrong has happened." - :type :error - :timeout 3000}))) + (st/emitf (dm/assign-exception error))) (js/console.group "Internal error:") (js/console.log "hint:" (or (ex-message error) (:hint error) (:message error))) (ex/ignoring - (js/console.error "repr: " (pr-str error)) - (js/console.error "data: " (clj->js error)) + (js/console.error (clj->js error)) (js/console.error "stack:" (.-stack error))) (js/console.groupEnd "Internal error:")))) - (defonce uncaught-error-handler (letfn [(on-error [event] (ptk/handle-error (unchecked-get event "error")) diff --git a/frontend/src/app/main/ui/static.cljs b/frontend/src/app/main/ui/static.cljs index ac00e1e7e..184aa8f78 100644 --- a/frontend/src/app/main/ui/static.cljs +++ b/frontend/src/app/main/ui/static.cljs @@ -88,8 +88,8 @@ [:div.exception-content [:div.container [:div.image i/icon-empty] - [:div.main-message "Internal Error"] - [:div.desc-message "Something bad happended on backend servers. Please retry the operation and if the problem persists, contact with support."] + [:div.main-message (tr "labels.internal-error.main-message")] + [:div.desc-message (tr "labels.internal-error.desc-message")] [:div.sign-info [:a.btn-primary.btn-small {:on-click (st/emitf (dm/assign-exception nil))} @@ -107,8 +107,5 @@ :service-unavailable [:& service-unavailable] - :server-error - [:& internal-error] - - nil)) + [:& internal-error]))