RequestInterceptor

public protocol RequestInterceptor : AnyObject

Protocol for intercepting and handling network requests and responses.

  • waitingForConnectivity(_:) Default implementation

    A URLSessionTask was put on hold by the URLSession while waiting for connectivity to come back

    Default Implementation

    Declaration

    Swift

    func waitingForConnectivity(_ task: URLSessionTask)

    Parameters

    task

    the URLSessionTask that was put on hold for connectivity

  • didComplete(_:with:) Default implementation

    A URLRequest was completed with a NetworkResult

    This event will be reported for each completed data task, which means that if a request is retried it might be reported more than once for each call.

    Default Implementation

    Declaration

    Swift

    func didComplete(_ request: URLRequest, with response: NetworkResult)

    Parameters

    request

    the URLRequest that was completed

    response

    the NetworkResult that was created with the response from the server or with the error

  • shouldRetry(_:retryCount:with:) Default implementation

    The client is asking if a given URLRequest should be retried.

    Default Implementation

    Declaration

    Swift

    func shouldRetry(_ request: URLRequest, retryCount: Int, with response: NetworkResult) -> RetryPolicy

    Parameters

    request

    the URLRequest to be retried

    retryCount

    the amount of retries that have already been sent so far

    response

    the NetworkResult for the last request sent