Skip to content

Commit

Permalink
Merge pull request #1167 from apollographql/update/just-break
Browse files Browse the repository at this point in the history
Update retry delegate change to breaking
  • Loading branch information
designatednerd authored Apr 21, 2020
2 parents e0ebca4 + d92ca68 commit 3325045
Showing 1 changed file with 3 additions and 41 deletions.
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

0 comments on commit 3325045

Please sign in to comment.