@@ -253,16 +253,17 @@ open class URLSessionTask : NSObject, NSCopying {
253
253
if let _protocol = self . _protocol {
254
254
_protocol. startLoading ( )
255
255
}
256
- else {
256
+ else if self . error == nil {
257
257
var userInfo : [ String : Any ] = [ NSLocalizedDescriptionKey: " unsupported URL " ]
258
258
if let url = self . originalRequest? . url {
259
259
userInfo [ NSURLErrorFailingURLErrorKey] = url
260
260
userInfo [ NSURLErrorFailingURLStringErrorKey] = url. absoluteString
261
261
}
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)
266
267
}
267
268
}
268
269
}
@@ -588,10 +589,10 @@ extension _ProtocolClient : URLProtocolClient {
588
589
589
590
func urlProtocol( _ protocol: URLProtocol , didFailWithError error: Error ) {
590
591
guard let task = `protocol`. task else { fatalError ( ) }
591
- urlSessionTask ( task, didFailWithError: error)
592
+ urlProtocol ( task : task, didFailWithError: error)
592
593
}
593
594
594
- func urlSessionTask ( _ task: URLSessionTask , didFailWithError error: Error ) {
595
+ func urlProtocol ( task: URLSessionTask , didFailWithError error: Error ) {
595
596
guard let session = task. session as? URLSession else { fatalError ( ) }
596
597
switch session. behaviour ( for: task) {
597
598
case . taskDelegate( let delegate) :
0 commit comments