@@ -88,7 +88,6 @@ open class URLSessionTask : NSObject, NSCopying {
88
88
self . _protocol = urlProtocol. init ( task: self , cachedResponse: nil , client: nil )
89
89
}
90
90
}
91
- guard self . _protocol != nil else { fatalError ( " Unable to find protocol handler for \( request) " ) }
92
91
}
93
92
deinit {
94
93
//TODO: Do we remove the EasyHandle from the session here? This might run on the wrong thread / queue.
@@ -251,7 +250,20 @@ open class URLSessionTask : NSObject, NSCopying {
251
250
self . updateTaskState ( )
252
251
if self . suspendCount == 0 {
253
252
self . workQueue. async {
254
- self . _protocol? . startLoading ( )
253
+ if let _protocol = self . _protocol {
254
+ _protocol. startLoading ( )
255
+ }
256
+ else {
257
+ var userInfo : [ String : Any ] = [ NSLocalizedDescriptionKey: " unsupported URL " ]
258
+ if let url = self . originalRequest? . url {
259
+ userInfo [ NSURLErrorFailingURLErrorKey] = url
260
+ userInfo [ NSURLErrorFailingURLStringErrorKey] = url. absoluteString
261
+ }
262
+ let error = NSError ( domain: NSURLErrorDomain,
263
+ code: URLError . unsupportedURL. rawValue,
264
+ userInfo: userInfo)
265
+ _ProtocolClient ( ) . urlProtocol ( task: self , didFailWithError: error)
266
+ }
255
267
}
256
268
}
257
269
}
@@ -576,6 +588,10 @@ extension _ProtocolClient : URLProtocolClient {
576
588
577
589
func urlProtocol( _ protocol: URLProtocol , didFailWithError error: Error ) {
578
590
guard let task = `protocol`. task else { fatalError ( ) }
591
+ urlProtocol ( task: task, didFailWithError: error)
592
+ }
593
+
594
+ func urlProtocol( task: URLSessionTask , didFailWithError error: Error ) {
579
595
guard let session = task. session as? URLSession else { fatalError ( ) }
580
596
switch session. behaviour ( for: task) {
581
597
case . taskDelegate( let delegate) :
0 commit comments