Tink.Error (Tink v0.1.1)

Copy Markdown View Source

Error struct and handling for Tink.

All API errors are wrapped in this struct for consistent error handling.

Error Types

  • :api_error - Tink API returned an error response
  • :network_error - Network/connection error
  • :timeout - Request timed out
  • :authentication_error - Auth failure
  • :rate_limit_error - Rate limit exceeded
  • :validation_error - Invalid parameters
  • :decode_error - Failed to decode response
  • :market_mismatch - Provider not available in requested market
  • :unknown - Unknown error

Examples

case Tink.Accounts.list(client) do
  {:ok, accounts} ->
    # Success

  {:error, %Tink.Error{type: :rate_limit_error}} ->
    # Handle rate limit

  {:error, %Tink.Error{status: 401}} ->
    # Handle unauthorized

  {:error, error} ->
    IO.inspect(error)
end

Summary

Functions

Returns a human-readable error message.

Creates an error from an HTTP client error.

Creates an error from an HTTP response.

Creates a new error struct.

Checks if an error is retryable.

Types

error_type()

@type error_type() ::
  :api_error
  | :network_error
  | :timeout
  | :authentication_error
  | :rate_limit_error
  | :validation_error
  | :decode_error
  | :market_mismatch
  | :unknown

t()

@type t() :: %Tink.Error{
  error_code: String.t() | nil,
  error_details: map() | nil,
  message: String.t(),
  original_error: term() | nil,
  request_id: String.t() | nil,
  status: integer() | nil,
  type: error_type()
}

Functions

format(error)

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

Returns a human-readable error message.

Examples

iex> error = Tink.Error.from_response(429, %{"errorMessage" => "Rate limit exceeded"})
iex> Tink.Error.format(error)
"[429] Rate limit exceeded (RATE_LIMIT_ERROR)"

from_http_error(error)

@spec from_http_error(map() | term()) :: t()

Creates an error from an HTTP client error.

Examples

iex> Tink.Error.from_http_error(%{type: :timeout, reason: "Request timed out"})
%Tink.Error{type: :timeout, message: "Request timed out"}

from_response(status, body)

@spec from_response(integer(), map() | String.t()) :: t()

Creates an error from an HTTP response.

Examples

iex> Tink.Error.from_response(400, %{"errorCode" => "INVALID_REQUEST"})
%Tink.Error{type: :api_error, status: 400, error_code: "INVALID_REQUEST"}

new(attrs)

@spec new(keyword()) :: t()

Creates a new error struct.

Examples

iex> Tink.Error.new(type: :network_error, message: "Connection failed")
%Tink.Error{type: :network_error, message: "Connection failed"}

retryable?(error)

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

Checks if an error is retryable.

Examples

iex> error = %Tink.Error{type: :network_error, message: ""}
iex> Tink.Error.retryable?(error)
true

iex> error = %Tink.Error{type: :validation_error, message: ""}
iex> Tink.Error.retryable?(error)
false