fix http-fetch: handle error status code

This commit is contained in:
Roman Volosovskyi 2017-03-07 12:36:13 +02:00
parent 15d3d758ad
commit 9e509d2f9a
1 changed files with 9 additions and 2 deletions

View File

@ -44,8 +44,15 @@
(-> (.fetch js/window url (clj->js {:method "GET"}))
(.then (fn [response]
(log response)
(.text response)))
(.then on-success)
[(.text response) (.-ok response)]))
(.then (fn [[response ok?]]
(cond
ok? (on-success response)
(and on-error (not ok?))
(on-error response)
:else false)))
(.catch (or on-error
(fn [error]
(show-popup "Error" (str error))))))))