This commit is contained in:
Roman Volosovskyi 2017-03-08 15:53:21 +02:00
parent 874bf16f97
commit bc9ec05de3
2 changed files with 12 additions and 1 deletions

View File

@ -37,6 +37,11 @@
(and dapp? dapp-url) (and dapp? dapp-url)
(http-get (s/join "/" [dapp-url commands-js]) (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 %])
#(dispatch [::validate-hash whisper-identity js-res/dapp-js])) #(dispatch [::validate-hash whisper-identity js-res/dapp-js]))

View File

@ -41,10 +41,16 @@
(defn http-get (defn http-get
([url on-success on-error] ([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"})) (-> (.fetch js/window url (clj->js {:method "GET"}))
(.then (fn [response] (.then (fn [response]
(log 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?]] (.then (fn [[response ok?]]
(cond (cond
ok? (on-success response) ok? (on-success response)