Skip to content

Commit 58902f0

Browse files
committed
Fix issue in URLSession:task:didCompleteWithError:
1 parent ffcf45e commit 58902f0

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

cocos/network/CCDownloader-apple.mm

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -418,26 +418,20 @@ - (void)URLSession:(NSURLSession *)session task :(NSURLSessionTask *)task
418418
else
419419
{
420420
NSInteger statusCode = ((NSHTTPURLResponse*)task.response).statusCode;
421-
std::vector<unsigned char> buf; // just a placeholder
422-
const char *orignalURL = [task.originalRequest.URL.absoluteString cStringUsingEncoding:NSUTF8StringEncoding];
423-
std::string errorMessage = "";
424421

425422
// Check for error status code
426423
if (statusCode >= 400)
427424
{
428-
errorMessage = cocos2d::StringUtils::format("Downloader: Failed to download %s with status code (%d)", orignalURL, (int)statusCode);
429-
}
430-
// Unknown issue
431-
else
432-
{
433-
errorMessage = cocos2d::StringUtils::format("Downloader: Failed to download %s with unknown error", orignalURL);
425+
std::vector<unsigned char> buf; // just a placeholder
426+
const char *orignalURL = [task.originalRequest.URL.absoluteString cStringUsingEncoding:NSUTF8StringEncoding];
427+
std::string errorMessage = cocos2d::StringUtils::format("Downloader: Failed to download %s with status code (%d)", orignalURL, (int)statusCode);
428+
429+
_outer->onTaskFinish(*[wrapper get],
430+
cocos2d::network::DownloadTask::ERROR_IMPL_INTERNAL,
431+
0,
432+
errorMessage,
433+
buf);
434434
}
435-
436-
_outer->onTaskFinish(*[wrapper get],
437-
cocos2d::network::DownloadTask::ERROR_IMPL_INTERNAL,
438-
0,
439-
errorMessage,
440-
buf);
441435
}
442436
}
443437
[self.taskDict removeObjectForKey:task];

0 commit comments

Comments
 (0)