Merge pull request #2668 from dreampiggy/bugfix_error_domains_check
Fix the black list error domain should filter specify SDWebImageErrorDomain codes which is indeed un-recoverable
This commit is contained in:
commit
51aab09fdd
|
@ -85,4 +85,16 @@ FOUNDATION_EXPORT UIImage * _Nullable SDImageLoaderDecodeProgressiveImageData(NS
|
||||||
progress:(nullable SDImageLoaderProgressBlock)progressBlock
|
progress:(nullable SDImageLoaderProgressBlock)progressBlock
|
||||||
completed:(nullable SDImageLoaderCompletedBlock)completedBlock;
|
completed:(nullable SDImageLoaderCompletedBlock)completedBlock;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Whether the error from image loader should be marked indded un-recoverable or not.
|
||||||
|
If this return YES, failed URL which does not using `SDWebImageRetryFailed` will be blocked into black list. Else not.
|
||||||
|
|
||||||
|
@param url The URL represent the image. Note this may not be a HTTP URL
|
||||||
|
@param error The URL's loading error, from previous `requestImageWithURL:options:context:progress:completed:` completedBlock's error.
|
||||||
|
@return Whether to block this url or not. Return YES to mark this URL as failed.
|
||||||
|
*/
|
||||||
|
- (BOOL)shouldBlockFailedURLWithURL:(nonnull NSURL *)url
|
||||||
|
error:(nonnull NSError *)error;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -100,4 +100,14 @@
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)shouldBlockFailedURLWithURL:(NSURL *)url error:(NSError *)error {
|
||||||
|
NSArray<id<SDImageLoader>> *loaders = self.loaders;
|
||||||
|
for (id<SDImageLoader> loader in loaders.reverseObjectEnumerator) {
|
||||||
|
if ([loader canRequestImageForURL:url]) {
|
||||||
|
return [loader shouldBlockFailedURLWithURL:url error:error];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -546,4 +546,25 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
return [self downloadImageWithURL:url options:downloaderOptions context:context progress:progressBlock completed:completedBlock];
|
return [self downloadImageWithURL:url options:downloaderOptions context:context progress:progressBlock completed:completedBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)shouldBlockFailedURLWithURL:(NSURL *)url error:(NSError *)error {
|
||||||
|
BOOL shouldBlockFailedURL;
|
||||||
|
// Filter the error domain and check error codes
|
||||||
|
if ([error.domain isEqualToString:SDWebImageErrorDomain]) {
|
||||||
|
shouldBlockFailedURL = ( error.code == SDWebImageErrorInvalidURL
|
||||||
|
|| error.code == SDWebImageErrorBadImageData);
|
||||||
|
} else if ([error.domain isEqualToString:NSURLErrorDomain]) {
|
||||||
|
shouldBlockFailedURL = ( error.code != NSURLErrorNotConnectedToInternet
|
||||||
|
&& error.code != NSURLErrorCancelled
|
||||||
|
&& error.code != NSURLErrorTimedOut
|
||||||
|
&& error.code != NSURLErrorInternationalRoamingOff
|
||||||
|
&& error.code != NSURLErrorDataNotAllowed
|
||||||
|
&& error.code != NSURLErrorCannotFindHost
|
||||||
|
&& error.code != NSURLErrorCannotConnectToHost
|
||||||
|
&& error.code != NSURLErrorNetworkConnectionLost);
|
||||||
|
} else {
|
||||||
|
shouldBlockFailedURL = NO;
|
||||||
|
}
|
||||||
|
return shouldBlockFailedURL;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -178,7 +178,7 @@ static id<SDImageLoader> _defaultImageLoader;
|
||||||
|
|
||||||
// Query cache process
|
// Query cache process
|
||||||
- (void)callCacheProcessForOperation:(nonnull SDWebImageCombinedOperation *)operation
|
- (void)callCacheProcessForOperation:(nonnull SDWebImageCombinedOperation *)operation
|
||||||
url:(nullable NSURL *)url
|
url:(nonnull NSURL *)url
|
||||||
options:(SDWebImageOptions)options
|
options:(SDWebImageOptions)options
|
||||||
context:(nullable SDWebImageContext *)context
|
context:(nullable SDWebImageContext *)context
|
||||||
progress:(nullable SDImageLoaderProgressBlock)progressBlock
|
progress:(nullable SDImageLoaderProgressBlock)progressBlock
|
||||||
|
@ -206,7 +206,7 @@ static id<SDImageLoader> _defaultImageLoader;
|
||||||
|
|
||||||
// Download process
|
// Download process
|
||||||
- (void)callDownloadProcessForOperation:(nonnull SDWebImageCombinedOperation *)operation
|
- (void)callDownloadProcessForOperation:(nonnull SDWebImageCombinedOperation *)operation
|
||||||
url:(nullable NSURL *)url
|
url:(nonnull NSURL *)url
|
||||||
options:(SDWebImageOptions)options
|
options:(SDWebImageOptions)options
|
||||||
context:(SDWebImageContext *)context
|
context:(SDWebImageContext *)context
|
||||||
cachedImage:(nullable UIImage *)cachedImage
|
cachedImage:(nullable UIImage *)cachedImage
|
||||||
|
@ -280,7 +280,7 @@ static id<SDImageLoader> _defaultImageLoader;
|
||||||
|
|
||||||
// Store cache process
|
// Store cache process
|
||||||
- (void)callStoreCacheProcessForOperation:(nonnull SDWebImageCombinedOperation *)operation
|
- (void)callStoreCacheProcessForOperation:(nonnull SDWebImageCombinedOperation *)operation
|
||||||
url:(nullable NSURL *)url
|
url:(nonnull NSURL *)url
|
||||||
options:(SDWebImageOptions)options
|
options:(SDWebImageOptions)options
|
||||||
context:(SDWebImageContext *)context
|
context:(SDWebImageContext *)context
|
||||||
downloadedImage:(nullable UIImage *)downloadedImage
|
downloadedImage:(nullable UIImage *)downloadedImage
|
||||||
|
@ -374,19 +374,7 @@ static id<SDImageLoader> _defaultImageLoader;
|
||||||
if ([self.delegate respondsToSelector:@selector(imageManager:shouldBlockFailedURL:withError:)]) {
|
if ([self.delegate respondsToSelector:@selector(imageManager:shouldBlockFailedURL:withError:)]) {
|
||||||
shouldBlockFailedURL = [self.delegate imageManager:self shouldBlockFailedURL:url withError:error];
|
shouldBlockFailedURL = [self.delegate imageManager:self shouldBlockFailedURL:url withError:error];
|
||||||
} else {
|
} else {
|
||||||
// Filter the error domain and check error codes
|
shouldBlockFailedURL = [self.imageLoader shouldBlockFailedURLWithURL:url error:error];
|
||||||
if ([error.domain isEqualToString:NSURLErrorDomain]) {
|
|
||||||
shouldBlockFailedURL = ( error.code != NSURLErrorNotConnectedToInternet
|
|
||||||
&& error.code != NSURLErrorCancelled
|
|
||||||
&& error.code != NSURLErrorTimedOut
|
|
||||||
&& error.code != NSURLErrorInternationalRoamingOff
|
|
||||||
&& error.code != NSURLErrorDataNotAllowed
|
|
||||||
&& error.code != NSURLErrorCannotFindHost
|
|
||||||
&& error.code != NSURLErrorCannotConnectToHost
|
|
||||||
&& error.code != NSURLErrorNetworkConnectionLost);
|
|
||||||
} else {
|
|
||||||
shouldBlockFailedURL = NO;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return shouldBlockFailedURL;
|
return shouldBlockFailedURL;
|
||||||
|
|
|
@ -50,4 +50,8 @@
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)shouldBlockFailedURLWithURL:(NSURL *)url error:(NSError *)error {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in New Issue