Back to Alamofire

RetryPolicy

docs/docsets/Alamofire.docset/Contents/Resources/Documents/Classes/RetryPolicy.html

5.12.05.8 KB
Original Source

RetryPolicy

open class RetryPolicy : @unchecked Sendable, RequestInterceptor

A retry policy that retries requests using an exponential backoff for allowed HTTP methods and HTTP status codes as well as certain types of networking errors.

`

                defaultRetryLimit
                `

The default retry limit for retry policies.

Declaration

Swift

public static let defaultRetryLimit: UInt

`

                defaultExponentialBackoffBase
                `

The default exponential backoff base for retry policies (must be a minimum of 2).

Declaration

Swift

public static let defaultExponentialBackoffBase: UInt

`

                defaultExponentialBackoffScale
                `

The default exponential backoff scale for retry policies.

Declaration

Swift

public static let defaultExponentialBackoffScale: Double

`

                defaultRetryableHTTPMethods
                `

The default HTTP methods to retry. See RFC 2616 - Section 9.1.2 for more information.

Declaration

Swift

public static let defaultRetryableHTTPMethods: Set<HTTPMethod>

`

                defaultRetryableHTTPStatusCodes
                `

The default HTTP status codes to retry. See RFC 2616 - Section 10 for more information.

Declaration

Swift

public static let defaultRetryableHTTPStatusCodes: Set<Int>

`

                defaultRetryableURLErrorCodes
                `

The default URL error codes to retry.

Declaration

Swift

public static let defaultRetryableURLErrorCodes: Set<URLError.Code>

`

                retryLimit
                `

The total number of times the request is allowed to be retried.

Declaration

Swift

public let retryLimit: UInt

`

                exponentialBackoffBase
                `

The base of the exponential backoff policy (should always be greater than or equal to 2).

Declaration

Swift

public let exponentialBackoffBase: UInt

`

                exponentialBackoffScale
                `

The scale of the exponential backoff.

Declaration

Swift

public let exponentialBackoffScale: Double

`

                retryableHTTPMethods
                `

The HTTP methods that are allowed to be retried.

Declaration

Swift

public let retryableHTTPMethods: Set<HTTPMethod>

`

                retryableHTTPStatusCodes
                `

The HTTP status codes that are automatically retried by the policy.

Declaration

Swift

public let retryableHTTPStatusCodes: Set<Int>

`

                retryableURLErrorCodes
                `

The URL error codes that are automatically retried by the policy.

Declaration

Swift

public let retryableURLErrorCodes: Set<URLError.Code>

`

                init(retryLimit:exponentialBackoffBase:exponentialBackoffScale:retryableHTTPMethods:retryableHTTPStatusCodes:retryableURLErrorCodes:)
                `

Creates a RetryPolicy from the specified parameters.

Declaration

Swift

public init(retryLimit: UInt = RetryPolicy.defaultRetryLimit,
            exponentialBackoffBase: UInt = RetryPolicy.defaultExponentialBackoffBase,
            exponentialBackoffScale: Double = RetryPolicy.defaultExponentialBackoffScale,
            retryableHTTPMethods: Set<HTTPMethod> = RetryPolicy.defaultRetryableHTTPMethods,
            retryableHTTPStatusCodes: Set<Int> = RetryPolicy.defaultRetryableHTTPStatusCodes,
            retryableURLErrorCodes: Set<URLError.Code> = RetryPolicy.defaultRetryableURLErrorCodes)

Parameters

| retryLimit |

The total number of times the request is allowed to be retried. 2 by default.

| | exponentialBackoffBase |

The base of the exponential backoff policy. 2 by default.

| | exponentialBackoffScale |

The scale of the exponential backoff. 0.5 by default.

| | retryableHTTPMethods |

The HTTP methods that are allowed to be retried. RetryPolicy.defaultRetryableHTTPMethods by default.

| | retryableHTTPStatusCodes |

The HTTP status codes that are automatically retried by the policy. RetryPolicy.defaultRetryableHTTPStatusCodes by default.

| | retryableURLErrorCodes |

The URL error codes that are automatically retried by the policy. RetryPolicy.defaultRetryableURLErrorCodes by default.

|

`

                retry(_:for:dueTo:completion:)
                `

Declaration

Swift

open func retry(_ request: Request,
                for session: Session,
                dueTo error: any Error,
                completion: @escaping @Sendable (RetryResult) -> Void)

`

                shouldRetry(request:dueTo:)
                `

Determines whether or not to retry the provided Request.

Declaration

Swift

open func shouldRetry(request: Request, dueTo error: any Error) -> Bool

Parameters

| request |

Request that failed due to the provided Error.

| | error |

Error encountered while executing the Request.

|

Return Value

Bool determining whether or not to retry the Request.