handling errors

This commit is contained in:
Bryce Covert
2018-04-09 14:46:10 -07:00
parent d69b1f2b81
commit 3da61b0057
3 changed files with 48 additions and 30 deletions

View File

@@ -33,18 +33,24 @@
(re-frame/reg-fx
:http
(fn [{:keys [method uri on-success body headers token]}]
(fn [{:keys [method uri on-success on-error body headers token]}]
(go
(let [headers (if token
(assoc headers "Authorization" (str "Token " token))
headers)]
(println headers)
(->> (http/request {:method method
:body body
:headers headers
:url uri})
(<! )
:body
(dates->date-times)
(conj on-success)
(re-frame/dispatch))))))
headers)
response (<! (http/request {:method method
:body body
:headers headers
:url uri}))]
(if (>= (:status response) 400)
(when on-error
(->> response
:body
(dates->date-times)
(conj on-error)
(re-frame/dispatch)))
(->> response
:body
(dates->date-times)
(conj on-success)
(re-frame/dispatch)))))))