RequestInterceptor
public protocol RequestInterceptor : AnyObject
Protocol for intercepting and handling network requests and responses.
-
An attempt of a
URLRequestcompleted with aNetworkResult.This event will be reported for each attempt, which means that if a request is retried it will be reported more than once for each call. It’s called on every interceptor before any retry decision is made, including when the client’s
maxRetryCounthas been reached.Declaration
Swift
func onAttemptResult(_ request: URLRequest, retryCount: Int, with result: NetworkResult)Parameters
requestthe
URLRequestthat was attemptedretryCountthe number of times this request had already been retried before this attempt, by any interceptor: 0 for the first attempt.
resultthe
NetworkResultthat was created with the response from the server or with the error -
The client is asking if a given
URLRequestshould be retried.Every interceptor must implement this method. Interceptors that only observe the completed requests return
.doNotRetry.Interceptors are consulted in reverse order, so the most recently added one is asked first. The first
RetryPolicyother than.doNotRetryis used, which means.doNotRetryis “no opinion”, not a veto: another interceptor may still retry the request.Declaration
Swift
func shouldRetry(_ request: URLRequest, consecutiveRetryCount: Int, with response: NetworkResult) -> RetryPolicyParameters
requestthe
URLRequestto be retriedconsecutiveRetryCountthe number of retries this interceptor proposed in a row right before this decision. It is 0 on the first failure and whenever the last retry was proposed by a different interceptor, so the count restarts, for example, after another interceptor waited for connectivity.
responsethe
NetworkResultfor the last request sent
View on GitHub