Tinkex.Error (Tinkex v0.3.4)

View Source

Error type for Tinkex operations.

Mirrors Python tinker error handling with categorization for retry logic.

Summary

Functions

Format error as string.

Create an error from an HTTP response.

Create a new error.

Check if error is retryable.

Check if error is a user error (not retryable).

Types

error_type()

@type error_type() ::
  :api_connection | :api_timeout | :api_status | :request_failed | :validation

t()

@type t() :: %Tinkex.Error{
  category: Tinkex.Types.RequestErrorCategory.t() | nil,
  data: map() | nil,
  message: String.t(),
  retry_after_ms: non_neg_integer() | nil,
  status: integer() | nil,
  type: error_type()
}

Functions

format(error)

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

Format error as string.

from_response(status, body)

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

Create an error from an HTTP response.

new(type, message, opts \\ [])

@spec new(error_type(), String.t(), keyword()) :: t()

Create a new error.

retryable?(error)

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

Check if error is retryable.

user_error?(arg1)

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

Check if error is a user error (not retryable).

Truth table:

  • category == :user → YES
  • status 4xx (except 408, 429) → YES
  • Everything else → NO