Move the block failed url logic into a separate method, filter the error codes not inside NSURLErrorDomain
This commit is contained in:
parent
cf1d993b97
commit
a1106d51f0
|
@ -247,20 +247,7 @@ static id<SDImageLoader> _defaultImageLoader;
|
||||||
// Image refresh hit the NSURLCache cache, do not call the completion block
|
// Image refresh hit the NSURLCache cache, do not call the completion block
|
||||||
} else if (error) {
|
} else if (error) {
|
||||||
[self callCompletionBlockForOperation:strongOperation completion:completedBlock error:error url:url];
|
[self callCompletionBlockForOperation:strongOperation completion:completedBlock error:error url:url];
|
||||||
BOOL shouldBlockFailedURL;
|
BOOL shouldBlockFailedURL = [self shouldBlockFailedURLWithURL:url error:error];
|
||||||
// Check whether we should block failed url
|
|
||||||
if ([self.delegate respondsToSelector:@selector(imageManager:shouldBlockFailedURL:withError:)]) {
|
|
||||||
shouldBlockFailedURL = [self.delegate imageManager:self shouldBlockFailedURL:url withError:error];
|
|
||||||
} else {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldBlockFailedURL) {
|
if (shouldBlockFailedURL) {
|
||||||
SD_LOCK(self.failedURLsLock);
|
SD_LOCK(self.failedURLsLock);
|
||||||
|
@ -380,6 +367,33 @@ static id<SDImageLoader> _defaultImageLoader;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)shouldBlockFailedURLWithURL:(nonnull NSURL *)url
|
||||||
|
error:(nonnull NSError *)error {
|
||||||
|
// Check whether we should block failed url
|
||||||
|
BOOL shouldBlockFailedURL;
|
||||||
|
if ([self.delegate respondsToSelector:@selector(imageManager:shouldBlockFailedURL:withError:)]) {
|
||||||
|
shouldBlockFailedURL = [self.delegate imageManager:self shouldBlockFailedURL:url withError:error];
|
||||||
|
} else {
|
||||||
|
NSString *domain = error.domain;
|
||||||
|
NSInteger code = error.code;
|
||||||
|
if ([domain isEqualToString:NSURLErrorDomain]) {
|
||||||
|
shouldBlockFailedURL = ( code != NSURLErrorNotConnectedToInternet
|
||||||
|
&& code != NSURLErrorCancelled
|
||||||
|
&& code != NSURLErrorTimedOut
|
||||||
|
&& code != NSURLErrorInternationalRoamingOff
|
||||||
|
&& code != NSURLErrorDataNotAllowed
|
||||||
|
&& code != NSURLErrorCannotFindHost
|
||||||
|
&& code != NSURLErrorCannotConnectToHost
|
||||||
|
&& code != NSURLErrorNetworkConnectionLost);
|
||||||
|
} else {
|
||||||
|
// Custom loader, don't do extra error code check
|
||||||
|
shouldBlockFailedURL = NO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return shouldBlockFailedURL;
|
||||||
|
}
|
||||||
|
|
||||||
- (SDWebImageContext *)processedContextWithContext:(SDWebImageContext *)context {
|
- (SDWebImageContext *)processedContextWithContext:(SDWebImageContext *)context {
|
||||||
SDWebImageMutableContext *mutableContext = [SDWebImageMutableContext dictionary];
|
SDWebImageMutableContext *mutableContext = [SDWebImageMutableContext dictionary];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue