clj / src / ird / errors.clj
175 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(ns ird.errors)

(defn api-error
  "Error returned by the ird API (non-2xx HTTP status). CODE is the
  machine-readable error code, STATUS the HTTP status, RESPONSE the parsed
  error body."
  [message code status response]
  (ex-info message
           {:type :ird/api-error
            :code code
            :status status
            :response response}))

(defn transport-error
  "Low-level failure talking to the API (connection failure, non-JSON body,
  etc.)."
  [message detail]
  (ex-info message
           {:type :ird/transport-error
            :detail detail}))

(defn config-error
  "Invalid client configuration passed to make-client."
  [message detail]
  (ex-info message
           {:type :ird/config-error
            :detail detail}))

(defn domain-denied
  "Client-side domain gate violation: the operation targets a domain that the
  client's :denied-domains/:allowed-domains configuration forbids. Thrown
  before any request reaches the API."
  [domain matched-pattern op]
  (ex-info (str "Domain gate: " (or domain "(unknown domain)")
                " may not be touched by " op)
           {:type :ird/domain-denied
            :domain domain
            :matched-pattern matched-pattern
            :op op}))

(defn api-error?
  "True when E is an :ird/api-error."
  [e]
  (= :ird/api-error (:type (ex-data e))))

(defn transport-error?
  "True when E is an :ird/transport-error."
  [e]
  (= :ird/transport-error (:type (ex-data e))))

(defn domain-denied?
  "True when E is an :ird/domain-denied gate violation."
  [e]
  (= :ird/domain-denied (:type (ex-data e))))

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/clj.git