0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-13 10:38:13 -05:00

Add UI related error handling under uxbox.ui ns.

Instead of on uxbox.state.
This commit is contained in:
Andrey Antukh 2016-05-16 13:28:26 +03:00
parent 05df84e89c
commit 3b56210bde
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -8,14 +8,18 @@
(ns uxbox.ui
(:require [sablono.core :as html :refer-macros [html]]
[promesa.core :as p]
[beicon.core :as rx]
[goog.dom :as gdom]
[rum.core :as rum]
[lentes.core :as l]
[uxbox.state :as st]
[uxbox.router :as r]
[uxbox.rstore :as rs]
[uxbox.locales :refer (tr)]
[uxbox.data.projects :as dp]
[uxbox.data.users :as udu]
[uxbox.data.auth :as dauth]
[uxbox.data.messages :as dmsg]
[uxbox.ui.icons :as i]
[uxbox.ui.lightbox :as ui-lightbox]
[uxbox.ui.auth :as ui-auth]
@ -34,6 +38,33 @@
(as-> (l/key :route) $
(l/focus-atom $ st/state)))
;; --- Error Handling
(defn- on-error
"A default error handler."
[error]
(cond
;; Unauthorized or Auth timeout
(and (:status error)
(:payload error)
(or (= (:status error) 403)
(= (:status error) 419)))
(rs/emit! (dauth/logout))
;; Network error
(= (:status error) 0)
(do
(dmsg/error! (tr "errors.network"))
(js/console.error "Stack:" (.-stack error)))
;; Something else
:else
(do
(dmsg/error! (tr "errors.generic"))
(js/console.error "Stack:" (.-stack error)))))
(rs/add-error-watcher :ui on-error)
;; --- Main App (Component)
(defn app-render