Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit cb5e570

Browse files
committed
Merge pull request #1085 from chrisze/master
[ASNetworkImageNode] Add error handler to ASNetworkImageNodeDelegate
2 parents 999e93f + a02a60f commit cb5e570

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

AsyncDisplayKit/ASNetworkImageNode.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ NS_ASSUME_NONNULL_BEGIN
9595

9696
@optional
9797

98+
/**
99+
* Notification that the image node failed to download the image.
100+
*
101+
* @param imageNode The sender.
102+
* @param error The error with details.
103+
*
104+
* @discussion Called on a background queue.
105+
*/
106+
- (void)imageNode:(ASNetworkImageNode *)imageNode didFailWithError:(NSError *)error;
107+
98108
/**
99109
* Notification that the image node finished decoding an image.
100110
*

AsyncDisplayKit/ASNetworkImageNode.mm

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,14 @@ - (void)_cancelImageDownload
168168
_cacheUUID = nil;
169169
}
170170

171-
- (void)_downloadImageWithCompletion:(void (^)(CGImageRef))finished
171+
- (void)_downloadImageWithCompletion:(void (^)(CGImageRef, NSError*))finished
172172
{
173173
_imageDownload = [_downloader downloadImageWithURL:_URL
174174
callbackQueue:dispatch_get_main_queue()
175175
downloadProgressBlock:NULL
176176
completion:^(CGImageRef responseImage, NSError *error) {
177177
if (finished != NULL) {
178-
finished(responseImage);
178+
finished(responseImage, error);
179179
}
180180
}];
181181
}
@@ -210,7 +210,7 @@ - (void)_lazilyLoadImageIfNecessary
210210
}
211211
} else {
212212
__weak __typeof__(self) weakSelf = self;
213-
void (^finished)(CGImageRef) = ^(CGImageRef responseImage) {
213+
void (^finished)(CGImageRef, NSError *) = ^(CGImageRef responseImage, NSError *error) {
214214
__typeof__(self) strongSelf = weakSelf;
215215
if (strongSelf == nil) {
216216
return;
@@ -232,6 +232,9 @@ - (void)_lazilyLoadImageIfNecessary
232232
if (responseImage != NULL) {
233233
[strongSelf->_delegate imageNode:strongSelf didLoadImage:strongSelf.image];
234234
}
235+
else if (error && [strongSelf->_delegate respondsToSelector:@selector(imageNode:didFailWithError:)]) {
236+
[strongSelf->_delegate imageNode:strongSelf didFailWithError:error];
237+
}
235238
};
236239

237240
if (_cache != nil) {
@@ -247,7 +250,7 @@ - (void)_lazilyLoadImageIfNecessary
247250
if (image == NULL && _downloader != nil) {
248251
[self _downloadImageWithCompletion:finished];
249252
} else {
250-
finished(image);
253+
finished(image, NULL);
251254
}
252255
};
253256

0 commit comments

Comments
 (0)