Added `SDWebImageErrorDownloadResponseKey` userInfo for better error report
This commit is contained in:
parent
43219b0739
commit
f3d68c9cc2
|
@ -191,6 +191,7 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
|
||||||
}
|
}
|
||||||
if (cachedResponse) {
|
if (cachedResponse) {
|
||||||
self.cachedData = cachedResponse.data;
|
self.cachedData = cachedResponse.data;
|
||||||
|
self.response = cachedResponse.response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +324,9 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
response = [self.responseModifier modifiedResponseWithResponse:response];
|
response = [self.responseModifier modifiedResponseWithResponse:response];
|
||||||
if (!response) {
|
if (!response) {
|
||||||
valid = NO;
|
valid = NO;
|
||||||
self.responseError = [NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorInvalidDownloadResponse userInfo:@{NSLocalizedDescriptionKey : @"Download marked as failed because response is nil"}];
|
self.responseError = [NSError errorWithDomain:SDWebImageErrorDomain
|
||||||
|
code:SDWebImageErrorInvalidDownloadResponse
|
||||||
|
userInfo:@{NSLocalizedDescriptionKey : @"Download marked as failed because response is nil"}];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,7 +345,9 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
valid = NO;
|
valid = NO;
|
||||||
self.responseError = [NSError errorWithDomain:SDWebImageErrorDomain
|
self.responseError = [NSError errorWithDomain:SDWebImageErrorDomain
|
||||||
code:SDWebImageErrorInvalidDownloadStatusCode
|
code:SDWebImageErrorInvalidDownloadStatusCode
|
||||||
userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Download marked as failed because of invalid response status code %ld", (long)statusCode], SDWebImageErrorDownloadStatusCodeKey: @(statusCode)}];
|
userInfo:@{NSLocalizedDescriptionKey : [NSString stringWithFormat:@"Download marked as failed because of invalid response status code %ld", (long)statusCode],
|
||||||
|
SDWebImageErrorDownloadStatusCodeKey : @(statusCode),
|
||||||
|
SDWebImageErrorDownloadResponseKey : response}];
|
||||||
}
|
}
|
||||||
// Check content type valid (defaults nil)
|
// Check content type valid (defaults nil)
|
||||||
NSString *contentType = [response isKindOfClass:NSHTTPURLResponse.class] ? ((NSHTTPURLResponse *)response).MIMEType : nil;
|
NSString *contentType = [response isKindOfClass:NSHTTPURLResponse.class] ? ((NSHTTPURLResponse *)response).MIMEType : nil;
|
||||||
|
@ -354,7 +359,9 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
valid = NO;
|
valid = NO;
|
||||||
self.responseError = [NSError errorWithDomain:SDWebImageErrorDomain
|
self.responseError = [NSError errorWithDomain:SDWebImageErrorDomain
|
||||||
code:SDWebImageErrorInvalidDownloadContentType
|
code:SDWebImageErrorInvalidDownloadContentType
|
||||||
userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Download marked as failed because of invalid response content type %@", contentType], SDWebImageErrorDownloadContentTypeKey: contentType}];
|
userInfo:@{NSLocalizedDescriptionKey : [NSString stringWithFormat:@"Download marked as failed because of invalid response content type %@", contentType],
|
||||||
|
SDWebImageErrorDownloadContentTypeKey : contentType,
|
||||||
|
SDWebImageErrorDownloadResponseKey : response}];
|
||||||
}
|
}
|
||||||
//'304 Not Modified' is an exceptional one
|
//'304 Not Modified' is an exceptional one
|
||||||
//URLSession current behavior will return 200 status code when the server respond 304 and URLCache hit. But this is not a standard behavior and we just add a check
|
//URLSession current behavior will return 200 status code when the server respond 304 and URLCache hit. But this is not a standard behavior and we just add a check
|
||||||
|
@ -362,7 +369,8 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
valid = NO;
|
valid = NO;
|
||||||
self.responseError = [NSError errorWithDomain:SDWebImageErrorDomain
|
self.responseError = [NSError errorWithDomain:SDWebImageErrorDomain
|
||||||
code:SDWebImageErrorCacheNotModified
|
code:SDWebImageErrorCacheNotModified
|
||||||
userInfo:@{NSLocalizedDescriptionKey: @"Download response status code is 304 not modified and ignored"}];
|
userInfo:@{NSLocalizedDescriptionKey: @"Download response status code is 304 not modified and ignored",
|
||||||
|
SDWebImageErrorDownloadResponseKey : response}];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
@ -495,7 +503,10 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
* then we should check if the cached data is equal to image data
|
* then we should check if the cached data is equal to image data
|
||||||
*/
|
*/
|
||||||
if (self.options & SDWebImageDownloaderIgnoreCachedResponse && [self.cachedData isEqualToData:imageData]) {
|
if (self.options & SDWebImageDownloaderIgnoreCachedResponse && [self.cachedData isEqualToData:imageData]) {
|
||||||
self.responseError = [NSError errorWithDomain:SDWebImageErrorDomain code:SDWebImageErrorCacheNotModified userInfo:@{NSLocalizedDescriptionKey : @"Downloaded image is not modified and ignored"}];
|
self.responseError = [NSError errorWithDomain:SDWebImageErrorDomain
|
||||||
|
code:SDWebImageErrorCacheNotModified
|
||||||
|
userInfo:@{NSLocalizedDescriptionKey : @"Downloaded image is not modified and ignored",
|
||||||
|
SDWebImageErrorDownloadResponseKey : self.response}];
|
||||||
// call completion block with not modified error
|
// call completion block with not modified error
|
||||||
[self callCompletionBlocksWithError:self.responseError];
|
[self callCompletionBlocksWithError:self.responseError];
|
||||||
[self done];
|
[self done];
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
FOUNDATION_EXPORT NSErrorDomain const _Nonnull SDWebImageErrorDomain;
|
FOUNDATION_EXPORT NSErrorDomain const _Nonnull SDWebImageErrorDomain;
|
||||||
|
|
||||||
|
/// The response instance for invalid download response (NSURLResponse *)
|
||||||
|
FOUNDATION_EXPORT NSErrorUserInfoKey const _Nonnull SDWebImageErrorDownloadResponseKey;
|
||||||
/// The HTTP status code for invalid download response (NSNumber *)
|
/// The HTTP status code for invalid download response (NSNumber *)
|
||||||
FOUNDATION_EXPORT NSErrorUserInfoKey const _Nonnull SDWebImageErrorDownloadStatusCodeKey;
|
FOUNDATION_EXPORT NSErrorUserInfoKey const _Nonnull SDWebImageErrorDownloadStatusCodeKey;
|
||||||
/// The HTTP MIME content type for invalid download response (NSString *)
|
/// The HTTP MIME content type for invalid download response (NSString *)
|
||||||
|
|
|
@ -10,5 +10,7 @@
|
||||||
#import "SDWebImageError.h"
|
#import "SDWebImageError.h"
|
||||||
|
|
||||||
NSErrorDomain const _Nonnull SDWebImageErrorDomain = @"SDWebImageErrorDomain";
|
NSErrorDomain const _Nonnull SDWebImageErrorDomain = @"SDWebImageErrorDomain";
|
||||||
|
|
||||||
|
NSErrorUserInfoKey const _Nonnull SDWebImageErrorDownloadResponseKey = @"SDWebImageErrorDownloadResponseKey";
|
||||||
NSErrorUserInfoKey const _Nonnull SDWebImageErrorDownloadStatusCodeKey = @"SDWebImageErrorDownloadStatusCodeKey";
|
NSErrorUserInfoKey const _Nonnull SDWebImageErrorDownloadStatusCodeKey = @"SDWebImageErrorDownloadStatusCodeKey";
|
||||||
NSErrorUserInfoKey const _Nonnull SDWebImageErrorDownloadContentTypeKey = @"SDWebImageErrorDownloadContentTypeKey";
|
NSErrorUserInfoKey const _Nonnull SDWebImageErrorDownloadContentTypeKey = @"SDWebImageErrorDownloadContentTypeKey";
|
||||||
|
|
Loading…
Reference in New Issue