From ba139d7d2c7a5ba0e4673145212042d66c7c0a54 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Fri, 20 May 2022 12:21:34 +0200 Subject: [PATCH] :bug: Fix unathorized redirect --- frontend/src/app/main/repo.cljs | 6 +++--- frontend/src/app/util/http.cljs | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/main/repo.cljs b/frontend/src/app/main/repo.cljs index 275b1ea10..cc2c8828f 100644 --- a/frontend/src/app/main/repo.cljs +++ b/frontend/src/app/main/repo.cljs @@ -53,13 +53,13 @@ ([id params {:keys [raw-transit?]}] (let [decode-transit (if raw-transit? - identity - (partial rx/map http/conditional-decode-transit))] + http/conditional-error-decode-transit + http/conditional-decode-transit)] (->> (http/send! {:method :get :uri (u/join base-uri "api/rpc/query/" (name id)) :credentials "include" :query params}) - (decode-transit) + (rx/map decode-transit) (rx/mapcat handle-response))))) (defn- send-mutation! diff --git a/frontend/src/app/util/http.cljs b/frontend/src/app/util/http.cljs index 5c890ac89..37c8cac35 100644 --- a/frontend/src/app/util/http.cljs +++ b/frontend/src/app/util/http.cljs @@ -143,6 +143,12 @@ (assoc response :body (t/decode-str body)) response))) +(defn conditional-error-decode-transit + [{:keys [body status] :as response}] + (if (and (>= status 400) (string? body)) + (assoc response :body (t/decode-str body)) + response)) + (defn success? [{:keys [status]}] (<= 200 status 299))