Structured error returned by every Setu SDK function.
All public functions return {:ok, result} or {:error, %SetuClient.Error{}}.
Error types
type | Meaning |
|---|---|
:api | Setu returned a structured HTTP error response |
:auth | HTTP 401 / 403 — bad or expired credentials |
:rate_limit | HTTP 429 — slow down; retry_after may be set |
:network | TCP / DNS / TLS failure; always retryable |
:validation | Client-side check failed; no HTTP call was made |
:decode | Response body could not be decoded |
Pattern matching
case SetuClient.Payments.UPI.create_dqr(cfg, merchant_id, params) do
{:ok, qr} ->
qr["intentLink"]
{:error, %SetuClient.Error{type: :validation, field: f, message: m}} ->
Logger.error("bad field #{f}: #{m}")
{:error, %SetuClient.Error{type: :rate_limit, retry_after: ra}} ->
backoff(ra)
{:error, err} ->
Logger.error(SetuClient.Error.message(err))
end
Summary
Functions
Builds an :api error from a non-2xx HTTP response.
Builds an :auth error for HTTP 401 / 403.
Builds a :decode error when JSON decoding fails.
Returns a human-readable error message.
Builds a :network error from a transport-level exception.
Builds a :rate_limit error for HTTP 429.
Returns true when the error is safe to retry.
Returns the Setu trace ID, or nil if unavailable.
Builds a :validation error. No HTTP call is made when this is returned.
Types
@type error_type() :: :api | :auth | :rate_limit | :network | :validation | :decode
@type t() :: %SetuClient.Error{ cause: term(), code: String.t() | nil, field: String.t() | nil, http_status: non_neg_integer() | nil, message: String.t(), retry_after: String.t() | nil, retryable: boolean(), trace_id: String.t() | nil, type: error_type() }
Functions
@spec api(non_neg_integer(), String.t(), String.t(), String.t() | nil) :: t()
Builds an :api error from a non-2xx HTTP response.
@spec auth(non_neg_integer(), String.t(), String.t() | nil) :: t()
Builds an :auth error for HTTP 401 / 403.
Builds a :decode error when JSON decoding fails.
Returns a human-readable error message.
Builds a :network error from a transport-level exception.
Builds a :rate_limit error for HTTP 429.
Returns true when the error is safe to retry.
Returns the Setu trace ID, or nil if unavailable.
Builds a :validation error. No HTTP call is made when this is returned.