(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))))