Daraja.HTTP.Retry (daraja v0.1.0)

Copy Markdown View Source

Opt-in HTTP retry with exponential backoff and jitter.

Disabled by default. Enable for idempotent operations such as OAuth token fetches:

config :daraja, :http_retry,
  enabled: true,
  max_attempts: 3,
  base_ms: 100,
  max_ms: 2_000,
  jitter: true

Daraja.Auth.fetch_token/1 respects this config. Payment POST endpoints do not retry automatically — wrap your own calls with run/2 when you have explicit idempotency guarantees.

Summary

Functions

Runs fun/0, retrying {:error, reason} results when retry is enabled and reason is retryable.

Types

config()

@type config() :: %{
  enabled: boolean(),
  max_attempts: pos_integer(),
  base_ms: pos_integer(),
  max_ms: pos_integer(),
  jitter: boolean()
}

Functions

run(fun, opts \\ [])

@spec run(
  (-> term()),
  keyword()
) :: term()

Runs fun/0, retrying {:error, reason} results when retry is enabled and reason is retryable.

Pass enabled: true in opts to force retries for a single call regardless of application config.