TypeSafe.Error (TypeSafe v0.2.2)

Copy Markdown View Source

Exception structs used by the SDK.

Every SDK failure surfaces as one of these structs. Functions that can fail return them in an {:error, exception} tuple, and the ! variants raise them. All the HTTP-level exceptions (TypeSafe.APIError and its siblings) share the same fields — :status, :body, :headers, :request_id, :endpoint and :message — so a single rescue/pattern can inspect any of them.

Categories

Status mapping

StatusException
400TypeSafe.BadRequestError
401TypeSafe.AuthenticationError
403TypeSafe.PermissionDeniedError
404TypeSafe.NotFoundError
422TypeSafe.UnprocessableEntityError
429TypeSafe.RateLimitError
5xxTypeSafe.InternalServerError
otherTypeSafe.APIError

Summary

Types

t()

Any exception struct the SDK may raise or return.

Functions

Build the exception struct that matches an HTTP error status.

Extract a human-readable message from a decoded error body, mirroring the shapes the API uses.

Types

t()

Any exception struct the SDK may raise or return.

Functions

api_error(status, body, headers, endpoint \\ nil)

@spec api_error(
  pos_integer(),
  term(),
  %{optional(String.t()) => String.t()},
  String.t() | nil
) ::
  TypeSafe.APIError.t()

Build the exception struct that matches an HTTP error status.

headers is a map of lowercased header names to string values. endpoint is a human-readable "METHOD URL" (without credentials) or nil.

extract_message(body)

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

Extract a human-readable message from a decoded error body, mirroring the shapes the API uses.

Returns nil when no message can be found.