From 7057e70cd5137dd4b98af449a4be3b8c25f04368 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Thu, 11 Apr 2019 21:57:04 +0800 Subject: [PATCH] Update the description about this error code, and fix one potential issue of callback --- SDWebImage/SDWebImageDownloaderOperation.m | 3 +++ SDWebImage/SDWebImageError.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index 2c78c810..d692dd24 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -128,6 +128,8 @@ typedef NSMutableDictionary SDCallbacksDictionary; @synchronized (self) { if (self.isCancelled) { self.finished = YES; + // Operation cancelled by user before sending the request + [self callCompletionBlocksWithError:[NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorDownloadCancelled userInfo:nil]]; [self reset]; return; } @@ -226,6 +228,7 @@ typedef NSMutableDictionary SDCallbacksDictionary; if (self.isExecuting) self.executing = NO; if (!self.isFinished) self.finished = YES; } else { + // Operation cancelled by user before sending the request [self callCompletionBlocksWithError:[NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorDownloadCancelled userInfo:nil]]; } diff --git a/SDWebImage/SDWebImageError.h b/SDWebImage/SDWebImageError.h index 2bbc092f..f26c3e6b 100644 --- a/SDWebImage/SDWebImageError.h +++ b/SDWebImage/SDWebImageError.h @@ -19,5 +19,5 @@ typedef NS_ERROR_ENUM(SDWebImageErrorDomain, SDWebImageError) { SDWebImageErrorCacheNotModified = 1002, // The remote location specify that the cached image is not modified, such as the HTTP response 304 code. It's useful for `SDWebImageRefreshCached` SDWebImageErrorInvalidDownloadOperation = 2000, // The image download operation is invalid, such as nil operation or unexpected error occur when operation initialized SDWebImageErrorInvalidDownloadStatusCode = 2001, // The image download response a invalid status code. You can check the status code in error's userInfo under `SDWebImageErrorDownloadStatusCodeKey` - SDWebImageErrorDownloadCancelled = 2002, // The image download operation is cancelled by user. + SDWebImageErrorDownloadCancelled = 2002, // The image download operation is cancelled by user before sending the request };