Skip to content

Commit

Permalink
Fixed conflicts after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
kimdv committed Oct 15, 2019
1 parent a4b5d36 commit ca2e22d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
8 changes: 0 additions & 8 deletions Sources/Apollo/GraphQLResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,4 @@ public final class GraphQLResponse<Operation: GraphQLOperation> {
return GraphQLResult(data: nil, errors: errors, source: .server, dependentKeys: nil)
}
}

func parseErrorsOnlyFast() -> [GraphQLError]? {
guard let errorsEntry = self.body["errors"] as? [JSONObject] else {
return nil
}

return errorsEntry.map(GraphQLError.init)
}
}
30 changes: 24 additions & 6 deletions Sources/Apollo/HTTPNetworkTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public class HTTPNetworkTransport {
error: error)

if let receivedError = error {
self?.handleErrorOrRetry(operation: operation,
self.handleErrorOrRetry(operation: operation,
files: files,
error: receivedError,
for: request,
Expand All @@ -162,7 +162,7 @@ public class HTTPNetworkTransport {
let unsuccessfulError = GraphQLHTTPResponseError(body: data,
response: httpResponse,
kind: .errorResponse)
self?.handleErrorOrRetry(operation: operation,
self.handleErrorOrRetry(operation: operation,
files: files,
error: unsuccessfulError,
for: request,
Expand All @@ -175,7 +175,7 @@ public class HTTPNetworkTransport {
let error = GraphQLHTTPResponseError(body: nil,
response: httpResponse,
kind: .invalidResponse)
self?.handleErrorOrRetry(operation: operation,
self.handleErrorOrRetry(operation: operation,
files: files,
error: error,
for: request,
Expand All @@ -188,7 +188,9 @@ public class HTTPNetworkTransport {
guard let body = try self.serializationFormat.deserialize(data: data) as? JSONObject else {
throw GraphQLHTTPResponseError(body: data, response: httpResponse, kind: .invalidResponse)
}

let graphQLResponse = GraphQLResponse(operation: operation, body: body)

if let errors = graphQLResponse.parseErrorsOnlyFast() {
// Handle specific errors from response
self.handleGraphQLErrorsIfNeeded(operation: operation,
Expand All @@ -200,7 +202,7 @@ public class HTTPNetworkTransport {
completionHandler(.success(graphQLResponse))
}
} catch let parsingError {
self?.handleErrorOrRetry(operation: operation,
self.handleErrorOrRetry(operation: operation,
files: files,
error: parsingError,
for: request,
Expand All @@ -226,12 +228,20 @@ public class HTTPNetworkTransport {
}

delegate.networkTransport(self, receivedGraphQLErrors: graphQLErrors, retryHandler: { [weak self] shouldRetry in
guard let self = self else {
// None of the rest of this really matters
return
}

guard shouldRetry else {
completionHandler(.success(response))
return
}

_ = self?.send(operation: operation, files: files, completionHandler: completionHandler)
_ = self.send(operation: operation,
isPersistedQueryRetry: self.enableAutoPersistedQueries,
files: files,
completionHandler: completionHandler)
})
}

Expand Down Expand Up @@ -275,12 +285,20 @@ public class HTTPNetworkTransport {
for: request,
response: response,
retryHandler: { [weak self] shouldRetry in
guard let self = self else {
// None of the rest of this really matters
return
}

guard shouldRetry else {
completionHandler(.failure(error))
return
}

_ = self?.send(operation: operation, files: files, completionHandler: completionHandler)
_ = self.send(operation: operation,
isPersistedQueryRetry: self.enableAutoPersistedQueries,
files: files,
completionHandler: completionHandler)
})
}

Expand Down

0 comments on commit ca2e22d

Please sign in to comment.