TypeSafe.Error exception (typesafe_ai v0.1.1)

Copy Markdown View Source

A failure returned as {:error, error} by the client.

Match :kind and, for HTTP errors, :status; message text is descriptive and is not a stable identifier. The client returns these errors instead of raising them during normal evaluation.

KindMeaning
:configurationInvalid client options or retry policy
:validationInvalid evaluation options, questions, or JSON input
:transportConnection, TLS, or socket failure
:timeoutOverall deadline exhausted, or a retry cannot fit within it
:overloadedClient capacity and queue are full
:httpNon-success HTTP response after the retry policy is applied
:invalid_responseMalformed, inconsistent, or oversized response
:unavailableClient process unavailable or shutting down

Library-generated errors omit server bodies and low-level exception details, which can contain credentials or user input. :status retains an HTTP status for HTTP errors and is otherwise usually nil. This is not a general-purpose redaction facility: new/3 preserves the message you supply.

See the errors and retries guide for handling examples.

Summary

Types

Failure category; match this field instead of message text.

t()

Failure category, descriptive message, and optional HTTP status.

Functions

Builds an error from the supplied description and optional HTTP status.

Types

kind()

@type kind() ::
  :configuration
  | :validation
  | :transport
  | :timeout
  | :overloaded
  | :http
  | :invalid_response
  | :unavailable

Failure category; match this field instead of message text.

t()

@type t() :: %TypeSafe.Error{
  __exception__: term(),
  kind: kind(),
  message: String.t(),
  status: pos_integer() | nil
}

Failure category, descriptive message, and optional HTTP status.

Functions

new(kind, message, status \\ nil)

@spec new(kind(), String.t(), pos_integer() | nil) :: t()

Builds an error from the supplied description and optional HTTP status.

The message is stored unchanged. Use a fixed description without credentials, request state, or response bodies when creating an error yourself.

Examples

iex> error = TypeSafe.Error.new(:http, "System One request failed", 401)
iex> {error.kind, error.status, Exception.message(error)}
{:http, 401, "System One request failed"}