# `Lei.HTTP.Retry`
[🔗](https://github.com/kitplummer/lowendinsight/blob/main/lib/lei/http/retry.ex#L1)

Retries an HTTPoison request on transient failures.

Replaces the `httpoison_retry` package, which has not been released since
2019 and does not allow httpoison 2 or 3 (ADR-003, 0.10.0).

A request is retried when it fails with a transport error that is likely to
pass (`:timeout`, `:connect_timeout`, `:closed`, `:nxdomain`) or when the
server answers 500. Anything else, including 404, is returned as it is.
After the last attempt the last result is returned, never raised.

Sleeps between attempts, so do not call it from a GenServer or a request
handler with a deadline.

# `result`

```elixir
@type result() :: {:ok, HTTPoison.Response.t()} | {:error, HTTPoison.Error.t()}
```

# `request`

```elixir
@spec request((-&gt; result()), keyword()) :: result()
```

Calls `request` until it succeeds or `max_attempts` calls have been made.

Options:
  * `:max_attempts` - total calls, including the first (default 5)
  * `:wait` - milliseconds between attempts (default 15_000)
  * `:sleep` - the sleep function, for tests (default `Process.sleep/1`)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
