Skip to content

Commit 7fd5066

Browse files
committed
Fix issue when net task is cancelled.
1 parent 3fabe51 commit 7fd5066

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

STNetTaskQueue/STHTTPNetTaskQueueHandler.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,12 @@ - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)data
179179

180180
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
181181
{
182-
NSData *data = [NSData dataWithData:_data];
183182
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response;
183+
if (!httpResponse) { // NSURLSessionTask is cancelled
184+
return;
185+
}
186+
187+
NSData *data = [NSData dataWithData:_data];
184188
if (httpResponse.statusCode >= 200 && httpResponse.statusCode < 300) {
185189
id responseObj = nil;
186190
NSError *error = nil;

0 commit comments

Comments
 (0)