From bc9ec05de37603eb27ce4fa2c2cee037063ff172 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 8 Mar 2017 15:53:21 +0200 Subject: [PATCH] fix #866 --- src/status_im/commands/handlers/loading.cljs | 5 +++++ src/status_im/utils/utils.cljs | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index 71d5b1ca0a..f5c0da206c 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -37,6 +37,11 @@ (and dapp? dapp-url) (http-get (s/join "/" [dapp-url commands-js]) + (fn [response] + (and + (string? (.text response)) + (when-let [content-type (.. response -headers (get "Content-Type"))] + (s/includes? "application/javascript" content-type)))) #(dispatch [::validate-hash whisper-identity %]) #(dispatch [::validate-hash whisper-identity js-res/dapp-js])) diff --git a/src/status_im/utils/utils.cljs b/src/status_im/utils/utils.cljs index 5754a47081..356e11b861 100644 --- a/src/status_im/utils/utils.cljs +++ b/src/status_im/utils/utils.cljs @@ -41,10 +41,16 @@ (defn http-get ([url on-success on-error] + (http-get url nil on-success on-error)) + ([url valid-response? on-success on-error] (-> (.fetch js/window url (clj->js {:method "GET"})) (.then (fn [response] (log response) - [(.text response) (.-ok response)])) + (let [ok? (.-ok response) + ok?' (if valid-response? + (and ok? (valid-response? response)) + ok?)] + [(.text response) ok?']))) (.then (fn [[response ok?]] (cond ok? (on-success response)