Remove the custom NSURLErrorCancelled case when URLSession task been cancelled

This commit is contained in:
DreamPiggy 2020-12-25 14:32:38 +08:00
parent d92c6cd945
commit d8961a3e32
2 changed files with 5 additions and 6 deletions

View File

@ -244,15 +244,13 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
if (!self.isFinished) self.finished = YES;
if (self.dataTask) {
// Cancel the URLSession, `URLSession:task:didCompleteWithError:` delegate callback will be ignored
[self.dataTask cancel];
self.dataTask = nil;
// Provide the same userInfo as URLSession if network is cancelled
// Don't relay on `URLSession:task:didCompleteWithError:` delegate callback because it may delay
[self callCompletionBlocksWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:@{NSLocalizedDescriptionKey: @"cancelled", NSURLErrorFailingURLErrorKey: self.request.URL, NSURLErrorFailingURLStringErrorKey: self.request.URL.absoluteString}]];
} else {
// Operation cancelled by user during sending the request
[self callCompletionBlocksWithError:[NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorCancelled userInfo:@{NSLocalizedDescriptionKey : @"Operation cancelled by user during sending the request"}]];
}
// Operation cancelled by user during sending the request
[self callCompletionBlocksWithError:[NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorCancelled userInfo:@{NSLocalizedDescriptionKey : @"Operation cancelled by user during sending the request"}]];
[self reset];
}

View File

@ -174,6 +174,7 @@
SDWebImageDownloadToken *token = [[SDWebImageDownloader sharedDownloader]
downloadImageWithURL:imageURL options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
expect(error).notTo.beNil();
expect(error.domain).equal(SDWebImageErrorDomain);
expect(error.code).equal(SDWebImageErrorCancelled);
}];
expect([SDWebImageDownloader sharedDownloader].currentDownloadCount).to.equal(1);