TypeSafeAPISDK.Error exception (TypeSafeAPISDK v0.1.0)

Copy Markdown View Source

Normalized errors from the TypeSafe API and its Pristine transport.

HTTP status mapping follows the TypeSafe client contract: 400, 401, 403, 404, 422, 429, and 5xx receive dedicated error types. Transport, cancellation, and response-decoding failures remain distinct.

Summary

Types

error_type()

@type error_type() ::
  :invalid_request
  | :runtime_capability
  | :configuration
  | :bad_request
  | :authentication
  | :permission_denied
  | :not_found
  | :unprocessable_entity
  | :rate_limit
  | :internal_server
  | :api_error
  | :connection
  | :timeout
  | :cancelled
  | :response_validation

t()

@type t() :: %TypeSafeAPISDK.Error{
  __exception__: true,
  body: term(),
  cause: term(),
  details: map(),
  endpoint: String.t() | nil,
  field_path: String.t() | nil,
  headers: map(),
  message: String.t(),
  path: [String.t()] | nil,
  raw_http_response: Pristine.Response.t() | nil,
  request_id: String.t() | nil,
  retry_after_ms: non_neg_integer() | nil,
  status: integer() | nil,
  type: error_type()
}

Functions

configuration(message)

@spec configuration(String.t()) :: t()

extract_message(body)

@spec extract_message(term()) :: String.t() | nil

invalid_request(path, reason, details \\ %{})

@spec invalid_request([String.t()], String.t(), map()) :: t()

metadata(error)

@spec metadata(t()) :: map()

parse_retry_after(headers)

@spec parse_retry_after(map() | list()) :: non_neg_integer() | nil

response_validation(field_path, body \\ nil)

@spec response_validation(String.t() | [String.t()], term()) :: t()

retry_after(error)

@spec retry_after(t()) :: non_neg_integer() | nil

retryable?(error, policy \\ %RetryPolicy{})

@spec retryable?(t(), TypeSafeAPISDK.RetryPolicy.t() | false) :: boolean()