Codat.Error (codat v1.0.0)

Copy Markdown View Source

Structured error types returned by all Codat API functions.

All API functions return {:ok, result} or {:error, %Codat.Error{}}.

Error Types

TypeHTTP StatusDescription
:unauthorized401Invalid or missing API key
:payment_required402Free tier limit exceeded
:forbidden403Insufficient permissions
:not_found404Resource or data type not found
:conflict409Data not yet ready or resource conflict
:rate_limited429Too many requests
:bad_request400Invalid request body or parameters
:server_error5xxCodat internal server error
:service_unavailable503Service temporarily unavailable
:network_errorN/ATCP/TLS/connection failure
:timeoutN/ARequest timed out
:json_decode_errorN/AUnexpected response body

Summary

Functions

Builds a %Codat.Error{} from a network/transport-level error.

Builds a %Codat.Error{} from an HTTP response map.

Human-readable string representation of the error.

Returns true if the error is considered retryable (transient).

Types

error_type()

@type error_type() ::
  :unauthorized
  | :payment_required
  | :forbidden
  | :not_found
  | :conflict
  | :rate_limited
  | :bad_request
  | :unprocessable
  | :server_error
  | :service_unavailable
  | :network_error
  | :timeout
  | :json_decode_error
  | :unknown

t()

@type t() :: %Codat.Error{
  correlation_id: String.t() | nil,
  detail: map() | nil,
  message: String.t() | nil,
  raw_body: String.t() | nil,
  retry_after: non_neg_integer() | nil,
  status_code: non_neg_integer() | nil,
  type: error_type()
}

Functions

from_exception(exc)

@spec from_exception(Exception.t()) :: t()

Builds a %Codat.Error{} from a network/transport-level error.

from_response(map)

@spec from_response(map()) :: t()

Builds a %Codat.Error{} from an HTTP response map.

message(error)

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

Human-readable string representation of the error.

retryable?(error)

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

Returns true if the error is considered retryable (transient).