docs/Classes/RetryPolicy.html
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.
Swift
public static let defaultRetryLimit: UInt
`
defaultExponentialBackoffBase
`
The default exponential backoff base for retry policies (must be a minimum of 2).
Swift
public static let defaultExponentialBackoffBase: UInt
`
defaultExponentialBackoffScale
`
The default exponential backoff scale for retry policies.
Swift
public static let defaultExponentialBackoffScale: Double
`
defaultRetryableHTTPMethods
`
The default HTTP methods to retry. See RFC 2616 - Section 9.1.2 for more information.
Swift
public static let defaultRetryableHTTPMethods: Set<HTTPMethod>
`
defaultRetryableHTTPStatusCodes
`
The default HTTP status codes to retry. See RFC 2616 - Section 10 for more information.
Swift
public static let defaultRetryableHTTPStatusCodes: Set<Int>
`
defaultRetryableURLErrorCodes
`
The default URL error codes to retry.
Swift
public static let defaultRetryableURLErrorCodes: Set<URLError.Code>
`
retryLimit
`
The total number of times the request is allowed to be retried.
Swift
public let retryLimit: UInt
`
exponentialBackoffBase
`
The base of the exponential backoff policy (should always be greater than or equal to 2).
Swift
public let exponentialBackoffBase: UInt
`
exponentialBackoffScale
`
The scale of the exponential backoff.
Swift
public let exponentialBackoffScale: Double
`
retryableHTTPMethods
`
The HTTP methods that are allowed to be retried.
Swift
public let retryableHTTPMethods: Set<HTTPMethod>
`
retryableHTTPStatusCodes
`
The HTTP status codes that are automatically retried by the policy.
Swift
public let retryableHTTPStatusCodes: Set<Int>
`
retryableURLErrorCodes
`
The URL error codes that are automatically retried by the policy.
Swift
public let retryableURLErrorCodes: Set<URLError.Code>
`
init(retryLimit:exponentialBackoffBase:exponentialBackoffScale:retryableHTTPMethods:retryableHTTPStatusCodes:retryableURLErrorCodes:)
`
Creates a RetryPolicy from the specified parameters.
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)
| 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:)
`
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.
Swift
open func shouldRetry(request: Request, dueTo error: any Error) -> Bool
| request |
Request that failed due to the provided Error.
|
| error |
Error encountered while executing the Request.
|
Bool determining whether or not to retry the Request.