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.h b/SDWebImage/Core/SDWebImageManager.h index c7e52ca9..36c3e4a5 100644 --- a/SDWebImage/Core/SDWebImageManager.h +++ b/SDWebImage/Core/SDWebImageManager.h @@ -261,6 +261,17 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager]; */ - (void)cancelAll; +/** + * Remove the specify URL from failed black list. + * @param url The failed URL. + */ +- (void)removeFailedURL:(nonnull NSURL *)url; + +/** + * Remove all the URL from failed black list. + */ +- (void)removeAllFailedURLs; + /** * Return the cache key for a given URL, does not considerate transformer or thumbnail. * @note This method does not have context option, only use the url and manager level cacheKeyFilter to generate the cache key. diff --git a/SDWebImage/Core/SDWebImageManager.m b/SDWebImage/Core/SDWebImageManager.m index 7b1fc22a..1f2bcdcc 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; } @@ -226,6 +228,21 @@ static id _defaultImageLoader; return isRunning; } +- (void)removeFailedURL:(NSURL *)url { + if (!url) { + return; + } + SD_LOCK(self.failedURLsLock); + [self.failedURLs removeObject:url]; + SD_UNLOCK(self.failedURLsLock); +} + +- (void)removeAllFailedURLs { + SD_LOCK(self.failedURLsLock); + [self.failedURLs removeAllObjects]; + SD_UNLOCK(self.failedURLsLock); +} + #pragma mark - Private // Query normal cache process