소스 검색

[Issue 1785] Fixed issue where adapt error was incorrectly sent to retrier.

The AdaptError is only for internal use and should never be sent back to any public APIs such as the retrier. Previously, the AdaptError was being incorrectly sent to the retrier instead of the underlying error. This commit fixes the issue and also adds tests to ensure this is working properly.
Christian Noon 9 년 전
부모
커밋
d2826a1132
2개의 변경된 파일14개의 추가작업 그리고 3개의 파일을 삭제
  1. 3 3
      Source/SessionManager.swift
  2. 11 0
      Tests/SessionManagerTests.swift

+ 3 - 3
Source/SessionManager.swift

@@ -283,7 +283,7 @@ open class SessionManager {
         let request = DataRequest(session: session, requestTask: requestTask, error: underlyingError)
 
         if let retrier = retrier, error is AdaptError {
-            allowRetrier(retrier, toRetry: request, with: error)
+            allowRetrier(retrier, toRetry: request, with: underlyingError)
         } else {
             if startRequestsImmediately { request.resume() }
         }
@@ -429,7 +429,7 @@ open class SessionManager {
         download.downloadDelegate.destination = destination
 
         if let retrier = retrier, error is AdaptError {
-            allowRetrier(retrier, toRetry: download, with: error)
+            allowRetrier(retrier, toRetry: download, with: underlyingError)
         } else {
             if startRequestsImmediately { download.resume() }
         }
@@ -756,7 +756,7 @@ open class SessionManager {
         let upload = UploadRequest(session: session, requestTask: uploadTask, error: underlyingError)
 
         if let retrier = retrier, error is AdaptError {
-            allowRetrier(retrier, toRetry: upload, with: error)
+            allowRetrier(retrier, toRetry: upload, with: underlyingError)
         } else {
             if startRequestsImmediately { upload.resume() }
         }

+ 11 - 0
Tests/SessionManagerTests.swift

@@ -52,6 +52,7 @@ class SessionManagerTestCase: BaseTestCase {
     private class RequestHandler: RequestAdapter, RequestRetrier {
         var adaptedCount = 0
         var retryCount = 0
+        var retryErrors: [Error] = []
 
         var shouldApplyAuthorizationHeader = false
         var throwsErrorOnSecondAdapt = false
@@ -77,6 +78,7 @@ class SessionManagerTestCase: BaseTestCase {
 
         func should(_ manager: SessionManager, retry request: Request, with error: Error, completion: @escaping RequestRetryCompletion) {
             retryCount += 1
+            retryErrors.append(error)
 
             if retryCount < 2 {
                 completion(true, 0.0)
@@ -89,6 +91,7 @@ class SessionManagerTestCase: BaseTestCase {
     private class UploadHandler: RequestAdapter, RequestRetrier {
         var adaptedCount = 0
         var retryCount = 0
+        var retryErrors: [Error] = []
 
         func adapt(_ urlRequest: URLRequest) throws -> URLRequest {
             adaptedCount += 1
@@ -100,6 +103,8 @@ class SessionManagerTestCase: BaseTestCase {
 
         func should(_ manager: SessionManager, retry request: Request, with error: Error, completion: @escaping RequestRetryCompletion) {
             retryCount += 1
+            retryErrors.append(error)
+
             completion(true, 0.0)
         }
     }
@@ -628,6 +633,8 @@ class SessionManagerTestCase: BaseTestCase {
         XCTAssertEqual(handler.adaptedCount, 2)
         XCTAssertEqual(handler.retryCount, 1)
         XCTAssertEqual(response?.result.isSuccess, true)
+
+        handler.retryErrors.forEach { XCTAssertFalse($0 is AdaptError) }
     }
 
     func testThatSessionManagerCallsRequestRetrierWhenDownloadInitiallyEncountersAdaptError() {
@@ -663,6 +670,8 @@ class SessionManagerTestCase: BaseTestCase {
         XCTAssertEqual(handler.adaptedCount, 2)
         XCTAssertEqual(handler.retryCount, 1)
         XCTAssertEqual(response?.result.isSuccess, true)
+
+        handler.retryErrors.forEach { XCTAssertFalse($0 is AdaptError) }
     }
 
     func testThatSessionManagerCallsRequestRetrierWhenUploadInitiallyEncountersAdaptError() {
@@ -692,6 +701,8 @@ class SessionManagerTestCase: BaseTestCase {
         XCTAssertEqual(handler.adaptedCount, 2)
         XCTAssertEqual(handler.retryCount, 1)
         XCTAssertEqual(response?.result.isSuccess, true)
+
+        handler.retryErrors.forEach { XCTAssertFalse($0 is AdaptError) }
     }
 
     func testThatSessionManagerCallsAdapterWhenRequestIsRetried() {