Add error for empty images. (#188)

This commit is contained in:
Garrett Moon
2016-04-13 10:09:38 -07:00
parent 0e81f77d16
commit bf1012741c
2 changed files with 10 additions and 1 deletions

View File

@@ -35,6 +35,8 @@ typedef NS_ENUM(NSUInteger, PINRemoteImageManagerError) {
PINRemoteImageManagerErrorFailedToProcessImage = 3,
/** The image in the cache was invalid */
PINRemoteImageManagerErrorInvalidItemInCache = 4,
/** The image at the URL was empty */
PINRemoteImageManagerErrorImageEmpty = 5,
};
/**

View File

@@ -802,18 +802,25 @@ static dispatch_once_t sharedDispatchToken;
#if PINRemoteImageLogging
if (error && error.code != NSURLErrorCancelled) {
PINLog(@"Failed downloading image: %@ with error: %@", url, error);
} else if (error == nil && responseObject == nil) {
} else if (error == nil && response.expectedContentLength == 0) {
PINLog(@"image is empty at URL: %@", url);
} else {
PINLog(@"Finished downloading image: %@", url);
}
#endif
if (error.code != NSURLErrorCancelled) {
[strongSelf lock];
PINRemoteImageDownloadTask *task = [strongSelf.tasks objectForKey:key];
NSData *data = task.progressImage.data;
[strongSelf unlock];
if (error == nil && data == nil) {
error = [NSError errorWithDomain:PINRemoteImageManagerErrorDomain
code:PINRemoteImageManagerErrorImageEmpty
userInfo:nil];
}
completion(data, error);
}
}];