exception.cljs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. (ns frontend.worker.rtc.exception
  2. "Exception list"
  3. (:require [logseq.common.defkeywords :refer [defkeywords]])
  4. (:import [missionary Cancelled]))
  5. (defkeywords
  6. :rtc.exception/ws-already-disconnected {:doc "Remote exception. current websocket conn is already disconnected and deleted by remote."}
  7. :rtc.exception/remote-graph-not-exist {:doc "Remote exception. e.g. push client-updates to a deleted graph."}
  8. :rtc.exception/remote-graph-not-ready {:doc "Remote exception. Remote graph is still creating."}
  9. :rtc.exception/remote-graph-lock-missing {:doc "
  10. Remote exception. Failed to remote graph lock isn't exist.
  11. It's a server internal error, shouldn't happen."}
  12. :rtc.exception/invalid-token {:doc "Local exception"}
  13. :rtc.exception/not-rtc-graph {:doc "Local exception. Trying to start rtc loop on a local-graph."}
  14. :rtc.exception/lock-failed {:doc "Local exception.
  15. Trying to start rtc loop but there's already one running, need to cancel that one first."}
  16. :rtc.exception/not-found-db-conn {:doc "Local exception. Cannot find db-conn by repo"}
  17. :rtc.exception/not-found-schema-version {:doc "Local exception. graph doesn't have :logseq.kv/schema-version value"}
  18. :rtc.exception/not-found-remote-schema-version {:doc "Local exception.
  19. graph doesn't have :logseq.kv/remote-schema-version value"}
  20. :rtc.exception/major-schema-version-mismatched {:doc "Local exception.
  21. local-schema-version, remote-schema-version, app-schema-version are not equal, cannot start rtc"}
  22. :rtc.exception/local-graph-too-old {:doc "Local exception.
  23. Local graph's tx is too old, need to pull earlier remote-data first"}
  24. :rtc.exception/get-s3-object-failed {:doc "Failed to fetch response from s3.
  25. When response from remote is too huge(> 32KB),
  26. the server will put it to s3 and return its presigned-url to clients."}
  27. :rtc.exception/bad-request-body {:doc "bad request body, rejected by server-schema"}
  28. :rtc.exception/not-allowed {:doc "this api-call is not allowed"}
  29. :rtc.exception/ws-timeout {:doc "websocket timeout"}
  30. :rtc.exception/fetch-user-rsa-key-pair-error {:doc "Failed to fetch user RSA key pair from server"}
  31. :rtc.exception/fetch-user-rsa-public-key-error {:doc "Failed to fetch user RSA public-key from server"}
  32. :rtc.exception/fetch-graph-aes-key-error {:doc "Failed to fetch graph AES key from server"}
  33. :rtc.exception/not-found-user-rsa-key-pair {:doc "user rsa-key-pair not found"}
  34. :rtc.exception/not-found-graph-aes-key {:doc "graph aes-key not found"})
  35. (def ex-remote-graph-lock-missing
  36. (ex-info "remote graph lock missing(server internal error)"
  37. {:type :rtc.exception/remote-graph-lock-missing}))
  38. (def ex-local-not-rtc-graph
  39. (ex-info "RTC is not supported for this local-graph" {:type :rtc.exception/not-rtc-graph}))
  40. (def ex-unknown-server-error
  41. (ex-info "Unknown server error" {:type :rtc.exception/unknown-server-error}))
  42. (defn e->ex-info
  43. [e]
  44. (cond
  45. (instance? Cancelled e) (ex-info "missionary.Cancelled" {:message (.-message e)})
  46. (instance? js/CloseEvent e) (ex-info "js/CloseEvent" {:type (.-type e)})
  47. ;; m/race-failure
  48. (and (instance? ExceptionInfo e)
  49. (contains? (ex-data e) :missionary.core/errors))
  50. (ex-info (ex-message e) (update (ex-data e) :missionary.core/errors (fn [errors] (map e->ex-info errors))))
  51. :else e))