Skip to content

Commit 7264039

Browse files
committed
Set error correctly
1 parent 7586508 commit 7264039

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Foundation/URLSession/URLSessionTask.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,17 @@ open class URLSessionTask : NSObject, NSCopying {
253253
if let _protocol = self._protocol {
254254
_protocol.startLoading()
255255
}
256-
else {
256+
else if self.error == nil {
257257
var userInfo: [String: Any] = [NSLocalizedDescriptionKey: "unsupported URL"]
258258
if let url = self.originalRequest?.url {
259259
userInfo[NSURLErrorFailingURLErrorKey] = url
260260
userInfo[NSURLErrorFailingURLStringErrorKey] = url.absoluteString
261261
}
262-
let error = NSError(domain: NSURLErrorDomain,
263-
code: NSURLErrorUnsupportedURL,
264-
userInfo: userInfo)
265-
_ProtocolClient().urlSessionTask(self, didFailWithError: URLError(_nsError: error))
262+
let urlError = URLError(_nsError: NSError(domain: NSURLErrorDomain,
263+
code: NSURLErrorUnsupportedURL,
264+
userInfo: userInfo))
265+
self.error = urlError
266+
_ProtocolClient().urlProtocol(task: self, didFailWithError: urlError)
266267
}
267268
}
268269
}
@@ -588,10 +589,10 @@ extension _ProtocolClient : URLProtocolClient {
588589

589590
func urlProtocol(_ protocol: URLProtocol, didFailWithError error: Error) {
590591
guard let task = `protocol`.task else { fatalError() }
591-
urlSessionTask(task, didFailWithError: error)
592+
urlProtocol(task: task, didFailWithError: error)
592593
}
593594

594-
func urlSessionTask(_ task: URLSessionTask, didFailWithError error: Error) {
595+
func urlProtocol(task: URLSessionTask, didFailWithError error: Error) {
595596
guard let session = task.session as? URLSession else { fatalError() }
596597
switch session.behaviour(for: task) {
597598
case .taskDelegate(let delegate):

0 commit comments

Comments
 (0)