From 0dd1d423978f86dd910e718ee031c1b9d5852eac Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Wed, 29 Apr 2020 21:38:20 +0800 Subject: [PATCH] Mark the black list error formal error code (which previouslly use `SDWebImageErrorInvalidURL`) --- SDWebImage/Core/SDWebImageError.h | 1 + SDWebImage/Core/SDWebImageManager.m | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/SDWebImage/Core/SDWebImageError.h b/SDWebImage/Core/SDWebImageError.h index e935ac97..dd84efa7 100644 --- a/SDWebImage/Core/SDWebImageError.h +++ b/SDWebImage/Core/SDWebImageError.h @@ -19,6 +19,7 @@ typedef NS_ERROR_ENUM(SDWebImageErrorDomain, SDWebImageError) { SDWebImageErrorInvalidURL = 1000, // The URL is invalid, such as nil URL or corrupted URL SDWebImageErrorBadImageData = 1001, // The image data can not be decoded to image, or the image data is empty 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` + SDWebImageErrorBlackListed = 1003, // The URL is blacklisted because of unrecoverable failsure marked by downloader (such as 404), you can use `.retryFailed` option to avoid this 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` SDWebImageErrorCancelled = 2002, // The image loading operation is cancelled before finished, during either async disk cache query, or waiting before actual network request. For actual network request error, check `NSURLErrorDomain` error domain and code. diff --git a/SDWebImage/Core/SDWebImageManager.m b/SDWebImage/Core/SDWebImageManager.m index 7b1fc22a..a4872846 100644 --- a/SDWebImage/Core/SDWebImageManager.m +++ b/SDWebImage/Core/SDWebImageManager.m @@ -194,7 +194,9 @@ static id _defaultImageLoader; } if (url.absoluteString.length == 0 || (!(options & SDWebImageRetryFailed) && isFailedUrl)) { - [self callCompletionBlockForOperation:operation completion:completedBlock error:[NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorInvalidURL userInfo:@{NSLocalizedDescriptionKey : @"Image url is nil"}] url:url]; + NSString *description = isFailedUrl ? @"Image url is blacklisted" : @"Image url is nil"; + NSInteger code = isFailedUrl ? SDWebImageErrorBlackListed : SDWebImageErrorInvalidURL; + [self callCompletionBlockForOperation:operation completion:completedBlock error:[NSError errorWithDomain:SDWebImageErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey : description}] url:url]; return operation; }