DefaultRetryPolicy

class DefaultRetryPolicy(val maxRetries: Int = DEFAULT_MAX_RETRIES, val retryNonIdempotent: Boolean = false, val backoffBaseMillis: Long = DEFAULT_BACKOFF_BASE_MILLIS, val backoffMaxMillis: Long = DEFAULT_BACKOFF_MAX_MILLIS, val isRetryableStatus: (Int) -> Boolean = { it == STATUS_TOO_MANY_REQUESTS || it >= STATUS_SERVER_ERROR }, random: Random = Random.Default) : RetryPolicy

The default RetryPolicy: retries transient failures — timeouts, lost connectivity, 429, and 5xx — with exponential backoff and full jitter, honoring a server Retry-After hint when present. Non-idempotent methods (POST/PATCH) are not retried unless retryNonIdempotent.

Parameters

maxRetries

maximum number of retries (beyond the initial attempt). 0 disables retry.

retryNonIdempotent

allow retrying POST/PATCH; off by default to avoid duplicate writes.

backoffBaseMillis

base delay; retry n waits a random value in [0, base * 2^(n-1)].

backoffMaxMillis

upper bound on a single backoff (and on an honored Retry-After).

isRetryableStatus

predicate selecting retryable HTTP status codes; defaults to 429 + 5xx.

random

jitter source, injectable for deterministic tests.

Constructors

Link copied to clipboard
constructor(maxRetries: Int = DEFAULT_MAX_RETRIES, retryNonIdempotent: Boolean = false, backoffBaseMillis: Long = DEFAULT_BACKOFF_BASE_MILLIS, backoffMaxMillis: Long = DEFAULT_BACKOFF_MAX_MILLIS, isRetryableStatus: (Int) -> Boolean = { it == STATUS_TOO_MANY_REQUESTS || it >= STATUS_SERVER_ERROR }, random: Random = Random.Default)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open override fun retryDelayMillis(attempt: Int, method: HttpMethod, error: NetworkError): Long?

The delay before the upcoming retry, or null to give up.