Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update retry delegate change to breaking #1167

Merged
merged 2 commits into from
Apr 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 3 additions & 41 deletions Sources/Apollo/HTTPNetworkTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,6 @@ public protocol HTTPNetworkTransportTaskCompletedDelegate: HTTPNetworkTransportD

/// Methods which will be called if an error is receieved at the network level.
public protocol HTTPNetworkTransportRetryDelegate: HTTPNetworkTransportDelegate {

/// Called when an error has been received after a request has been sent to the server to see if an operation should be retried or not.
/// NOTE: Don't just call the `retryHandler` with `true` all the time, or you can potentially wind up in an infinite loop of errors
///
/// - Parameters:
/// - networkTransport: The network transport which received the error
/// - error: The received error
/// - request: The URLRequest which generated the error
/// - response: [Optional] Any response received when the error was generated
/// - retryHandler: A closure indicating whether the operation should be retried. Asyncrhonous to allow for re-authentication or other async operations to complete.
@available(*, deprecated, message: "Use networkTransport(_:receivedError:for:,response:continueHandler:) instead")
func networkTransport(_ networkTransport: HTTPNetworkTransport,
receivedError error: Error,
for request: URLRequest,
response: URLResponse?,
retryHandler: @escaping (_ shouldRetry: Bool) -> Void)

/// Called when an error has been received after a request has been sent to the server to see if an operation should be retried or not.
/// NOTE: Don't just call the `continueHandler` with `.retry` all the time, or you can potentially wind up in an infinite loop of errors
Expand All @@ -82,31 +66,6 @@ public protocol HTTPNetworkTransportRetryDelegate: HTTPNetworkTransportDelegate
continueHandler: @escaping (_ action: HTTPNetworkTransport.ContinueAction) -> Void)
}

public extension HTTPNetworkTransportRetryDelegate {

func networkTransport(_ networkTransport: HTTPNetworkTransport,
receivedError error: Error,
for request: URLRequest,
response: URLResponse?,
retryHandler: @escaping (_ shouldRetry: Bool) -> Void) {
retryHandler(false)
}

func networkTransport(_ networkTransport: HTTPNetworkTransport,
receivedError error: Error,
for request: URLRequest,
response: URLResponse?,
continueHandler: @escaping (_ action: HTTPNetworkTransport.ContinueAction) -> Void) {
self.networkTransport(networkTransport, receivedError: error, for: request, response: response) { (_ shouldRetry: Bool) in
if shouldRetry {
continueHandler(.retry)
} else {
continueHandler(.fail(error))
}
}
}
}

// MARK: -

/// Methods which will be called after some kind of response has been received and it contains GraphQLErrors.
Expand Down Expand Up @@ -135,8 +94,11 @@ public protocol HTTPNetworkTransportGraphQLErrorDelegate: HTTPNetworkTransportDe
/// A network transport that uses HTTP POST requests to send GraphQL operations to a server, and that uses `URLSession` as the networking implementation.
public class HTTPNetworkTransport {

/// The action to take when retrying
public enum ContinueAction {
/// Directly retry the action
case retry
/// Fail with the specified error.
case fail(_ error: Error)
}

Expand Down