TruelayerClient.Error exception (truelayer_client v1.0.0)

Copy Markdown View Source

Structured error type for all TruelayerClient operations.

Every public API function returns {:ok, result} or {:error, %TruelayerClient.Error{}}.

Fields

  • :type - machine-readable error category atom
  • :status - HTTP status code (nil for non-HTTP errors)
  • :trace_id - Tl-Trace-Id header value for support
  • :should_retry - whether TrueLayer indicated Tl-Should-Retry: true
  • :title - RFC 7807 error title
  • :detail - RFC 7807 error detail
  • :errors - per-field validation errors (400 responses)
  • :reason - underlying reason for non-API errors

Examples

case TruelayerClient.Payments.get_payment(client, id) do
  {:ok, payment} -> payment
  {:error, %TruelayerClient.Error{type: :not_found}} -> nil
  {:error, %TruelayerClient.Error{trace_id: tid} = err} ->
    Logger.error("TrueLayer error trace=#{tid}: #{Exception.message(err)}")
end

Summary

Functions

Returns true for 409 Conflict errors.

Build an Error from an API response.

Build a network/transport error.

Returns true for 404 Not Found errors.

Returns true for 429 Rate Limited errors.

Returns true when the error is safe to retry.

Returns true for 5xx Server errors.

Build a signing-not-configured error.

Returns true for 401 Unauthorized errors.

Types

error_type()

@type error_type() ::
  :api_error
  | :auth_error
  | :validation_error
  | :not_found
  | :unauthorized
  | :forbidden
  | :conflict
  | :rate_limited
  | :server_error
  | :signing_required
  | :replay_attack
  | :signature_invalid
  | :network_error
  | :decode_error
  | :timeout
  | :unknown

t()

@type t() :: %TruelayerClient.Error{
  __exception__: true,
  detail: String.t() | nil,
  errors: [map()] | nil,
  reason: term(),
  should_retry: boolean(),
  status: non_neg_integer() | nil,
  title: String.t() | nil,
  trace_id: String.t() | nil,
  type: error_type()
}

Functions

conflict?(arg1)

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

Returns true for 409 Conflict errors.

from_response(body, headers, status)

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

Build an Error from an API response.

network(reason)

@spec network(term()) :: t()

Build a network/transport error.

not_found?(arg1)

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

Returns true for 404 Not Found errors.

rate_limited?(arg1)

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

Returns true for 429 Rate Limited errors.

retryable?(error)

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

Returns true when the error is safe to retry.

server_error?(arg1)

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

Returns true for 5xx Server errors.

signing_required()

@spec signing_required() :: t()

Build a signing-not-configured error.

unauthorized?(arg1)

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

Returns true for 401 Unauthorized errors.