Fix incorrect handling of error message timeouts.

This commit is contained in:
Andrey Antukh 2017-02-21 17:49:17 +01:00
parent 8f08a23615
commit 0bb8fa7e06
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
2 changed files with 6 additions and 11 deletions

View file

@ -51,31 +51,26 @@
(defn- on-error
"A default error handler."
[{:keys [status] :as error}]
(js/console.log "on-error:" (pr-str error))
(js/console.log "stack:" (.-stack error))
(js/console.error "on-error:" (pr-str error))
(reset! st/loader false)
(cond
;; Unauthorized or Auth timeout
(and (:status error)
(or (= (:status error) 403)
(= (:status error) 419)))
(st/emit! (logout))
(ts/schedule 100 #(st/emit! (logout)))
;; Conflict
(= status 412)
(st/emit! (uum/error (tr "errors.conflict")))
(ts/schedule 100 #(st/emit! (uum/error (tr "errors.conflict"))))
;; Network error
(= (:status error) 0)
(do
(st/emit! (uum/error (tr "errors.network")))
(js/console.error "Stack:" (.-stack error)))
(ts/schedule 100 #(st/emit! (uum/error (tr "errors.network"))))
;; Something else
:else
(do
(st/emit! (uum/error (tr "errors.generic")))
(js/console.error "Stack:" (.-stack error)))))
(ts/schedule 100 #(st/emit! (uum/error (tr "errors.generic"))))))
(set! st/*on-error* on-error)

View file

@ -2,7 +2,7 @@
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2016-2017 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.util.timers)