Treat image URL with response status code >= 400 as errors (fix #79)

This commit is contained in:
Olivier Poitrey 2012-03-19 19:12:14 +01:00
parent 1cf1703ec1
commit 24f0842ea0
1 changed files with 21 additions and 0 deletions

View File

@ -104,6 +104,27 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot
#pragma mark NSURLConnection (delegate)
- (void)connection:(NSURLConnection *)aConnection didReceiveResponse:(NSURLResponse *)response
{
if ([((NSHTTPURLResponse *)response) statusCode] >= 400)
{
[aConnection cancel];
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:nil];
if ([delegate respondsToSelector:@selector(imageDownloader:didFailWithError:)])
{
NSError *error = [[NSError alloc] initWithDomain:NSURLErrorDomain
code:[((NSHTTPURLResponse *)response) statusCode]
userInfo:nil];
[delegate performSelector:@selector(imageDownloader:didFailWithError:) withObject:self withObject:error];
}
self.connection = nil;
self.imageData = nil;
}
}
- (void)connection:(NSURLConnection *)aConnection didReceiveData:(NSData *)data
{
[imageData appendData:data];