Enhance(sync): serveral enhancements in sync (#10134)

* enhance(sync): 1. dont clear-tokens when refresh-token failed

2. log invalid json when fail to parse api json body,
   usually, it's returned by firewall (e.g. a XML)
3. handle exceptions carefully in frontend.fs.sync

* enhance(sync): update avoid reentrancy related code

* rename exp to guard-ex
This commit is contained in:
rcmerci
2023-09-04 17:27:51 +08:00
committed by GitHub
parent 98bff93439
commit 2d34af9f6a
3 changed files with 287 additions and 253 deletions

View File

@@ -12,7 +12,8 @@
[cljs.core.async :as async :refer [go <!]]
[goog.crypt.Sha256]
[goog.crypt.Hmac]
[goog.crypt :as crypt]))
[goog.crypt :as crypt]
[frontend.handler.notification :as notification]))
(defn set-preferred-format!
[format]
@@ -143,7 +144,7 @@
nil ; do nothing
(not (http/unexceptional-status? (:status resp)))
(clear-tokens true)
(notification/show! "exceptional status when refresh-token" :warning true)
:else ; ok
(when (and (:id_token (:body resp)) (:access_token (:body resp)))
@@ -199,14 +200,14 @@
(state/clear-user-info!)
(state/pub-event! [:user/logout]))
(defn upgrade []
(defn upgrade []
(let [base-upgrade-url "https://logseqdemo.lemonsqueezy.com/checkout/buy/13e194b5-c927-41a8-af58-ed1a36d6000d"
user-uuid (user-uuid)
url (cond-> base-upgrade-url
user-uuid (str "?checkout[custom][user_uuid]=" (name user-uuid)))]
(println " ~~~ LEMON: " url " ~~~ ")
(js/window.open url)))
; (js/window.open
; (js/window.open
; "https://logseqdemo.lemonsqueezy.com/checkout/buy/13e194b5-c927-41a8-af58-ed1a36d6000d"))
(defn <ensure-id&access-token
@@ -218,7 +219,7 @@
(<! (<refresh-id-token&access-token))
(when (or (nil? (state/get-auth-id-token))
(-> (state/get-auth-id-token) parse-jwt expired?))
(ex-info "empty or expired token and refresh failed" {})))))
(ex-info "empty or expired token and refresh failed" {:anom :expired-token})))))
(defn <user-uuid
[]