From e3faddeb6ba222469758a1c7135a3dd8ac6d8197 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 19 Aug 2020 13:05:38 +0200 Subject: [PATCH] :arrow_up: Update potok dependency. --- frontend/deps.edn | 13 ++++----- frontend/src/app/main/repo.cljs | 5 +++- frontend/src/app/main/store.cljs | 4 +-- frontend/src/app/main/ui.cljs | 46 +++++++++++--------------------- 4 files changed, 29 insertions(+), 39 deletions(-) diff --git a/frontend/deps.edn b/frontend/deps.edn index ce6a044a5..7852f004e 100644 --- a/frontend/deps.edn +++ b/frontend/deps.edn @@ -11,14 +11,18 @@ danlentz/clj-uuid {:mvn/version "0.1.9"} frankiesardo/linked {:mvn/version "1.3.0"} - funcool/beicon {:mvn/version "2020.05.08-2"} - funcool/cuerdas {:mvn/version "2020.03.26-3"} funcool/lentes {:mvn/version "1.4.0-SNAPSHOT"} + funcool/beicon {:mvn/version "2020.05.08-2"} + funcool/cuerdas {:mvn/version "2020.03.26-3"} funcool/okulary {:mvn/version "2020.04.14-0"} - funcool/potok {:mvn/version "2.8.0-SNAPSHOT"} + funcool/potok {:mvn/version "2020.08.10-2"} funcool/promesa {:mvn/version "5.1.0"} funcool/rumext {:mvn/version "2020.05.22-1"} + + lambdaisland/uri {:mvn/version "1.3.45" + :exclusions [org.clojure/data.json]} + } :aliases {:dev @@ -35,9 +39,6 @@ thheller/shadow-cljs {:mvn/version "2.10.19"} - lambdaisland/uri {:mvn/version "1.3.45" - :exclusions [org.clojure/data.json]} - ;; i18n parsing carocad/parcera {:mvn/version "0.11.0"} org.antlr/antlr4-runtime {:mvn/version "4.7"}}} diff --git a/frontend/src/app/main/repo.cljs b/frontend/src/app/main/repo.cljs index 02577b181..2444ec95b 100644 --- a/frontend/src/app/main/repo.cljs +++ b/frontend/src/app/main/repo.cljs @@ -23,9 +23,12 @@ (http/client-error? response) (rx/throw (:body response)) + (http/server-error? response) + (rx/throw (:body response)) + :else (rx/throw {:type :unexpected - :code (:error response)}))) + :response response}))) (defn send-query! [id params] diff --git a/frontend/src/app/main/store.cljs b/frontend/src/app/main/store.cljs index de7ca0bd9..b65165f3b 100644 --- a/frontend/src/app/main/store.cljs +++ b/frontend/src/app/main/store.cljs @@ -17,9 +17,9 @@ (def ^:dynamic *on-error* identity) -(defonce state (l/atom {})) +(defonce state (l/atom {})) (defonce loader (l/atom false)) -(defonce store (ptk/store {:on-error #(*on-error* %)})) +(defonce store (ptk/store {:resolve ptk/resolve})) (defonce stream (ptk/input-stream store)) (defn- repr-event diff --git a/frontend/src/app/main/ui.cljs b/frontend/src/app/main/ui.cljs index 2cd4e3767..7b6bd6433 100644 --- a/frontend/src/app/main/ui.cljs +++ b/frontend/src/app/main/ui.cljs @@ -151,35 +151,21 @@ ;; --- Error Handling -(defn- on-error - "A default error handler." - [{:keys [type code] :as error}] - (reset! st/loader false) - (cond - (and (map? error) - (= :validation type) - (= :spec-validation code)) - (do - (println "============ SERVER RESPONSE ERROR ================") - (println (:explain error)) - (println "============ END SERVER RESPONSE ERROR ================")) +(defmethod ptk/handle-error :validation + [error] + (js/console.error (if (map? error) (pr-str error) error)) + (when-let [explain (:explain error)] + (println "============ SERVER RESPONSE ERROR ================") + (println explain) + (println "============ END SERVER RESPONSE ERROR ================"))) - ;; Unauthorized or Auth timeout - (and (map? error) - (= :authentication type) - (= :unauthorized code)) - (ts/schedule 0 #(st/emit! logout)) +(defmethod ptk/handle-error :authentication + [error] + (ts/schedule 0 #(st/emit! logout))) - ;; Network error - (and (map? error) - (= :unexpected type) - (= :abort code)) - (ts/schedule 100 #(st/emit! (dm/error (tr "errors.network")))) - - ;; Something else - :else - (do - (js/console.error error) - (ts/schedule 100 #(st/emit! (dm/error (tr "errors.generic"))))))) - -(set! st/*on-error* on-error) +(defmethod ptk/handle-error :default + [error] + (js/console.error (if (map? error) (pr-str error) error)) + (ts/schedule 100 #(st/emit! (dm/show {:content "Something wrong has happened." + :type :error + :timeout 5000}))))