Retries a request on errors.
Request Options
:retry- can be one of the following::safe_transient(default) - retry safe (GET/HEAD) requests on one of:HTTP 408/429/500/502/503/504 responses
Req.TransportErrorwithreason: :timeout | :econnrefused | :closedReq.HTTPErrorwithprotocol: :http2, reason: :unprocessed | :pool_not_available
:transient- same as:safe_transientexcept retries all HTTP methods (POST, DELETE, etc.)fun- a 2-arity function that accepts aReq.Requestand either aReq.Responseor an exception struct and returns one of the following:true- retry using the default delay described under:retry_delaybelow.{:delay, milliseconds}- retry with the given delay.false/nil- don't retry.
false- don't retry.
:retry_delay- if not set, which is the default, the retry delay is determined by the value of theRetry-Afterheader on HTTP 429/503 responses. If the header is not set, or the header value is negative, the default delay follows a simple exponential backoff with jitter, for example: 0.949s, 1.97s, 3.87s, 7.55s, ...:retry_delaycan be set to a function that receives the retry count (starting at 0) and returns the delay, the number of milliseconds to sleep before making another attempt.:retry_log_level- the log level to emit retry logs at. Can also be set tofalseto disable logging these messages. Defaults to:warning.:max_retries- maximum number of retry attempts, defaults to3(for a total of4requests to the server, including the initial one.)
Examples
iex> Req.get!("https://httpbingo.org/status/500,200").status
# 08:43:19.101 [warning] retry: got response with status 500, will retry in 941ms, 2 attempts left
# 08:43:22.958 [warning] retry: got response with status 500, will retry in 1877ms, 1 attempt left
200