ClearBank.Error exception (ClearBank v1.0.0)

Copy Markdown View Source

Represents a ClearBank API error.

Fields

  • :status - HTTP status code (e.g., 400, 409, 429)
  • :code - ClearBank error code string if available
  • :message - Human-readable error description
  • :details - Raw error map from the API response body
  • :request_id - The X-Request-Id from the original request
  • :correlation_id - The X-Correlation-Id returned by ClearBank (store for support)

Common status codes

  • 400 - Bad request (invalid payload, missing required field)
  • 401 - Unauthorised (invalid/expired API token)
  • 403 - Forbidden
  • 404 - Not found
  • 409 - Conflict (duplicate X-Request-Id)
  • 422 - Unprocessable entity
  • 429 - Rate limited (back off and retry)
  • 500 - Internal server error (retry with same X-Request-Id)
  • 503 - Service unavailable (check Retry-After header and retry)

Summary

Functions

Builds a generic %ClearBank.Error{} from an exception or reason.

Builds a %ClearBank.Error{} from a response map (status + headers + body). Accepts any struct or map with :status, :headers, :body fields.

Returns true if the error is retryable (5xx or 429).

Types

t()

@type t() :: %ClearBank.Error{
  __exception__: true,
  code: String.t() | nil,
  correlation_id: String.t() | nil,
  details: map() | nil,
  message: String.t(),
  request_id: String.t() | nil,
  status: non_neg_integer() | nil
}

Functions

from_exception(ex)

@spec from_exception(term()) :: t()

Builds a generic %ClearBank.Error{} from an exception or reason.

from_response(resp, request_id \\ nil)

@spec from_response(term(), String.t() | nil) :: t()

Builds a %ClearBank.Error{} from a response map (status + headers + body). Accepts any struct or map with :status, :headers, :body fields.

retryable?(arg1)

@spec retryable?(t()) :: boolean()

Returns true if the error is retryable (5xx or 429).