Skip to content

Commit 69abd6d

Browse files
committed
Handling crash in URLSessionTask
1 parent 5ffa3c8 commit 69abd6d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Foundation/URLSession/URLSessionTask.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,8 @@ extension _ProtocolClient : URLProtocolClient {
570570
func urlProtocolDidFinishLoading(_ protocol: URLProtocol) {
571571
guard let task = `protocol`.task else { fatalError() }
572572
guard let session = task.session as? URLSession else { fatalError() }
573-
guard let response = task.response as? HTTPURLResponse else { fatalError("No response") }
574-
if response.statusCode == 401 {
573+
guard let urlResponse = task.response else { fatalError("No response") }
574+
if let response = urlResponse as? HTTPURLResponse, response.statusCode == 401 {
575575
if let protectionSpace = createProtectionSpace(response) {
576576
//TODO: Fetch and set proposed credentials if they exist
577577
let authenticationChallenge = URLAuthenticationChallenge(protectionSpace: protectionSpace, proposedCredential: nil,

0 commit comments

Comments
 (0)