Error model for the UniRate API client.
Every error the client raises is a clojure.lang.ExceptionInfo (created with
ex-info) carrying a :unirate/error-type keyword in its ex-data. A caller
can therefore catch clojure.lang.ExceptionInfo to handle any failure, or
branch on the error type:
(try
(unirate.client/get-rate client "USD" "EUR")
(catch clojure.lang.ExceptionInfo e
(case (:unirate/error-type (ex-data e))
:authentication (handle-bad-key)
:rate-limit (back-off)
:invalid-currency (warn)
(rethrow e))))
The keyword set is the Clojure equivalent of the typed exception hierarchy in the other UniRate clients:
| error-type | HTTP | meaning |
|---|---|---|
| :invalid-date | 400 | malformed date / invalid request params |
| :authentication | 401 | missing or invalid API key |
| :invalid-currency | 404 | unknown currency or no data available |
| :rate-limit | 429 | request quota exceeded |
| :api | * | any other non-2xx (403 Pro-gate, 503, ...) |
| :unirate | — | transport / parse / generic failure (base) |
Error model for the UniRate API client.
Every error the client raises is a `clojure.lang.ExceptionInfo` (created with
`ex-info`) carrying a `:unirate/error-type` keyword in its `ex-data`. A caller
can therefore catch `clojure.lang.ExceptionInfo` to handle any failure, or
branch on the error type:
(try
(unirate.client/get-rate client "USD" "EUR")
(catch clojure.lang.ExceptionInfo e
(case (:unirate/error-type (ex-data e))
:authentication (handle-bad-key)
:rate-limit (back-off)
:invalid-currency (warn)
(rethrow e))))
The keyword set is the Clojure equivalent of the typed exception hierarchy in
the other UniRate clients:
| error-type | HTTP | meaning |
|-------------------|------|--------------------------------------------|
| :invalid-date | 400 | malformed date / invalid request params |
| :authentication | 401 | missing or invalid API key |
| :invalid-currency | 404 | unknown currency or no data available |
| :rate-limit | 429 | request quota exceeded |
| :api | * | any other non-2xx (403 Pro-gate, 503, ...) |
| :unirate | — | transport / parse / generic failure (base) |(api-error status body)Any other non-success HTTP response — most notably HTTP 403 on the Pro-gated
historical endpoints when called with a free-tier key, and HTTP 503 when the
service is unavailable. The originating :status and (trimmed)
:response-body are carried in the ex-data.
Any other non-success HTTP response — most notably HTTP 403 on the Pro-gated historical endpoints when called with a free-tier key, and HTTP 503 when the service is unavailable. The originating `:status` and (trimmed) `:response-body` are carried in the `ex-data`.
(authentication-error)HTTP 401 — the API key is missing or invalid.
HTTP 401 — the API key is missing or invalid.
(invalid-currency-error)HTTP 404 — an unknown currency code or no data available.
HTTP 404 — an unknown currency code or no data available.
(invalid-date-error)HTTP 400 — a malformed date or other invalid request parameters.
HTTP 400 — a malformed date or other invalid request parameters.
(map-status status body)Map an HTTP status code (and response body) to the appropriate error.
Map an HTTP status code (and response body) to the appropriate error.
(rate-limit-error)HTTP 429 — the account has exceeded its request quota.
HTTP 429 — the account has exceeded its request quota.
(unirate-error msg)(unirate-error msg data)The base error: a transport, parse, or otherwise generic failure.
All other errors share the same ex-data shape but with a more specific
:unirate/error-type.
The base error: a transport, parse, or otherwise generic failure. All other errors share the same `ex-data` shape but with a more specific `:unirate/error-type`.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |