Railsr.Error exception (Railsr v1.0.0)

Copy Markdown View Source

Structured error type returned by all railsr public functions.

All public resource functions return {:ok, struct} or {:error, %Railsr.Error{}}.

Fields

  • :type — machine-readable error category atom
  • :message — human-readable description
  • :status — HTTP status code (nil for network/internal errors)
  • :code — Railsr API error code string (e.g. "ERROR_ENTITY_NOT_FOUND")
  • :request_id — value of X-Request-Id header from Railsr for support tracing
  • :details — raw decoded body map for additional context
  • :retryable? — whether the request is safe to retry

Error Types

TypeMeaning
:unauthorized401 — invalid/expired token
:forbidden403 — insufficient OAuth scope
:not_found404 — resource does not exist
:conflict409 — duplicate resource
:unprocessable422 — validation failure
:rate_limited429 — too many requests
:server_error5xx — Railsr internal error
:circuit_opencircuit breaker tripped
:timeoutrequest exceeded :timeout config
:networkTCP-level connectivity error
:unknownanything else

Summary

Functions

Build a Railsr.Error from a non-HTTP exception (timeout, network, etc.).

Build a Railsr.Error from an HTTP response body + status.

Types

error_type()

@type error_type() ::
  :unauthorized
  | :forbidden
  | :not_found
  | :conflict
  | :unprocessable
  | :rate_limited
  | :server_error
  | :circuit_open
  | :timeout
  | :network
  | :unknown

t()

@type t() :: %Railsr.Error{
  __exception__: true,
  code: String.t() | nil,
  details: map() | nil,
  message: String.t(),
  request_id: String.t() | nil,
  retryable?: boolean(),
  status: non_neg_integer() | nil,
  type: error_type()
}

Functions

from_exception(exc)

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

Build a Railsr.Error from a non-HTTP exception (timeout, network, etc.).

from_response(status, body, headers \\ %{})

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

Build a Railsr.Error from an HTTP response body + status.