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.
-
The default retry limit for retry policies.
Declaration
Swift
public static let defaultRetryLimit: UInt -
The default exponential backoff base for retry policies (must be a minimum of 2).
Declaration
Swift
public static let defaultExponentialBackoffBase: UInt -
The default exponential backoff scale for retry policies.
Declaration
Swift
public static let defaultExponentialBackoffScale: Double -
The default HTTP methods to retry. See RFC 2616 - Section 9.1.2 for more information.
Declaration
Swift
public static let defaultRetryableHTTPMethods: Set<HTTPMethod> -
The default HTTP status codes to retry. See RFC 2616 - Section 10 for more information.
Declaration
Swift
public static let defaultRetryableHTTPStatusCodes: Set<Int> -
The default URL error codes to retry.
Declaration
Swift
public static let defaultRetryableURLErrorCodes: Set<URLError.Code> -
The total number of times the request is allowed to be retried.
Declaration
Swift
public let retryLimit: UInt -
The base of the exponential backoff policy (should always be greater than or equal to 2).
Declaration
Swift
public let exponentialBackoffBase: UInt -
The scale of the exponential backoff.
Declaration
Swift
public let exponentialBackoffScale: Double -
The HTTP methods that are allowed to be retried.
Declaration
Swift
public let retryableHTTPMethods: Set<HTTPMethod> -
The HTTP status codes that are automatically retried by the policy.
Declaration
Swift
public let retryableHTTPStatusCodes: Set<Int> -
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
RetryPolicyfrom 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
retryLimitThe total number of times the request is allowed to be retried.
2by default.exponentialBackoffBaseThe base of the exponential backoff policy.
2by default.exponentialBackoffScaleThe scale of the exponential backoff.
0.5by default.retryableHTTPMethodsThe HTTP methods that are allowed to be retried.
RetryPolicy.defaultRetryableHTTPMethodsby default.retryableHTTPStatusCodesThe HTTP status codes that are automatically retried by the policy.
RetryPolicy.defaultRetryableHTTPStatusCodesby default.retryableURLErrorCodesThe URL error codes that are automatically retried by the policy.
RetryPolicy.defaultRetryableURLErrorCodesby default. -
Declaration
Swift
open func retry(_ request: Request, for session: Session, dueTo error: any Error, completion: @escaping (RetryResult) -> Void) -
Determines whether or not to retry the provided
Request.Declaration
Swift
open func shouldRetry(request: Request, dueTo error: any Error) -> BoolParameters
requestRequestthat failed due to the providedError.errorErrorencountered while executing theRequest.Return Value
Booldetermining whether or not to retry theRequest.
View on GitHub
Install in Dash