LatticeStripe.RetryStrategy behaviour (LatticeStripe v0.2.0)

Copy Markdown View Source

Behaviour for controlling retry logic on failed Stripe API requests.

Implement this behaviour to customize retry decisions. The default implementation (LatticeStripe.RetryStrategy.Default) follows Stripe's official SDK retry conventions.

Example

defmodule MyApp.RetryStrategy do
  @behaviour LatticeStripe.RetryStrategy

  @impl true
  def retry?(attempt, context) do
    if attempt <= 5 and context.status in [429, 500, 502, 503] do
      {:retry, attempt * 1000}
    else
      :stop
    end
  end
end

Summary

Types

context()

@type context() :: %{
  error: LatticeStripe.Error.t() | nil,
  status: pos_integer() | nil,
  headers: [{String.t(), String.t()}],
  stripe_should_retry: boolean() | nil,
  method: atom(),
  idempotency_key: String.t() | nil
}

Callbacks

retry?(attempt, context)

@callback retry?(attempt :: pos_integer(), context()) ::
  {:retry, delay_ms :: non_neg_integer()} | :stop