Skip to content

Commit 0c7b0f4

Browse files
author
Mateusz Zajac
committed
Finish url session when an error occurs. Ex. No internet connection
1 parent 5e1ac8d commit 0c7b0f4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Sources/WebRequest/Delivery/FileDownloadWebRequestDelivery.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,13 @@ open class FileDownloadWebRequestDelivery : HTTPWebRequestDelivery, URLSessionDo
5656
if let error = error { print("\(#function) - \(error)") }
5757
self.webRequest = nil
5858
}
59+
60+
open func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
61+
guard let error = error,
62+
let errorCode = self.parseError(error),
63+
let request = self.webRequest else { return }
64+
print("\(#function) - \(error)")
65+
try? complete(request: request, errorCode: errorCode)
66+
self.webRequest = nil
67+
}
5968
}

0 commit comments

Comments
 (0)