From 8c1d46efbef11634c2315f6aeef17d299dabf7bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Gra=CC=88ser?= Date: Wed, 2 Dec 2020 17:52:53 +0100 Subject: [PATCH] Don't call download competion handler if error is nil --- Sources/Jetworking/Client/Client.swift | 5 ++++- Tests/JetworkingTests/ClientTests/ClientTests.swift | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/Jetworking/Client/Client.swift b/Sources/Jetworking/Client/Client.swift index 8dbe182..ec49b86 100644 --- a/Sources/Jetworking/Client/Client.swift +++ b/Sources/Jetworking/Client/Client.swift @@ -356,7 +356,10 @@ extension Client: DownloadExecutorDelegate { public func downloadExecutor(_ downloadTask: URLSessionDownloadTask, didCompleteWithError error: Error?) { // TODO handle response before calling the completion - guard let completionHandler = executingDownloads[downloadTask.identifier]?.completionHandler else { return } + guard + let completionHandler = executingDownloads[downloadTask.identifier]?.completionHandler, + let error = error + else { return } enqueue(completionHandler(nil, downloadTask.response, error)) } } diff --git a/Tests/JetworkingTests/ClientTests/ClientTests.swift b/Tests/JetworkingTests/ClientTests/ClientTests.swift index aa87893..ec406fb 100644 --- a/Tests/JetworkingTests/ClientTests/ClientTests.swift +++ b/Tests/JetworkingTests/ClientTests/ClientTests.swift @@ -255,7 +255,10 @@ final class ClientTests: XCTestCase { } ) { localURL, response, error in dispatchPrecondition(condition: .onQueue(DispatchQueue.main)) - guard let localURL = localURL else { return } + guard let localURL = localURL else { + XCTFail("Failed to unwrap url") + return + } do { let documentsURL = try FileManager.default.url(