mirror of
https://github.com/penpot/penpot.git
synced 2025-06-04 01:11:41 +02:00
♻️ Refactor error handling.
This commit is contained in:
parent
b4ba9d4375
commit
bea093e8da
17 changed files with 578 additions and 334 deletions
|
@ -15,34 +15,32 @@
|
|||
[app.util.http-api :as http]))
|
||||
|
||||
(defn- handle-response
|
||||
[response]
|
||||
[{:keys [status body] :as response}]
|
||||
(cond
|
||||
(http/success? response)
|
||||
(rx/of (:body response))
|
||||
(= 204 status)
|
||||
(rx/empty)
|
||||
|
||||
(= (:status response) 400)
|
||||
(rx/throw (:body response))
|
||||
(= 502 status)
|
||||
(rx/throw {:type :bad-gateway})
|
||||
|
||||
(= (:status response) 401)
|
||||
(rx/throw {:type :authentication
|
||||
:code :not-authenticated})
|
||||
|
||||
(= (:status response) 403)
|
||||
(rx/throw {:type :authorization
|
||||
:code :not-authorized})
|
||||
|
||||
(= (:status response) 404)
|
||||
(rx/throw (:body response))
|
||||
(= 503 status)
|
||||
(rx/throw {:type :service-unavailable})
|
||||
|
||||
(= 0 (:status response))
|
||||
(rx/throw {:type :offline})
|
||||
|
||||
(and (= 200 status)
|
||||
(coll? body))
|
||||
(rx/of body)
|
||||
|
||||
(and (>= status 400)
|
||||
(map? body))
|
||||
(rx/throw body)
|
||||
|
||||
:else
|
||||
(rx/throw (merge {:type :server-error
|
||||
:status (:status response)}
|
||||
(:body response)))))
|
||||
|
||||
|
||||
(rx/throw {:type :unexpected-error
|
||||
:status status
|
||||
:data body})))
|
||||
|
||||
(defn send-query!
|
||||
[id params]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue