Skip to content

Commit

Permalink
T 1164100: Add check for nil request URL (#166)
Browse files Browse the repository at this point in the history
* Update URLSessionClient.swift

* Added comment.

* URLSessionClientError enum case name change
  • Loading branch information
ruchiupgade-mb committed Oct 22, 2022
1 parent b28cd97 commit 5fa6640
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/Conduit/Networking/URLSessionClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ private typealias SessionCompletionHandler = (URLSession.AuthChallengeDispositio
public enum URLSessionClientError: Error {
case noResponse
case requestTimeout
case missingURLInMiddlewareRequest
}

/// Pipes requests through provided middleware and queues them into a single NSURLSession
Expand Down Expand Up @@ -132,6 +133,14 @@ public struct URLSessionClient: URLSessionClientType {

logger.verbose("Finished processing request through middleware pipeline ✓")

// This is an edge case. In `refreshBearerTokenWithin` method of Auth class we are delibertely making the request URL
// as nil. Since the request URL is nil, the data task is not initialized and we do not get the call back.
// To fix this we have added a nil check. If the URL is nil, we are returning a call back with missingURL error.
guard modifiedRequest.url != nil else {
completion(nil, nil, URLSessionClientError.missingURLInMiddlewareRequest)
return
}

// Finally, send the request
// Once tasks are created, the operation moves to the connection queue,
// so even though the pipeline is serial, requests run in parallel
Expand Down

0 comments on commit 5fa6640

Please sign in to comment.