Commit 1b1116c9 authored by Felix Paul Kühne's avatar Felix Paul Kühne

VLCHTTPFileDownloader: improve error reporting

parent a702fdf0
......@@ -14,7 +14,7 @@
- (void)downloadEnded;
@optional
- (void)downloadFailedWithError:(NSError *)error;
- (void)downloadFailedWithErrorDescription:(NSString *)description;
- (void)progressUpdatedTo:(CGFloat)percentage;
@end
......
......@@ -55,6 +55,10 @@
_expectedDownloadSize = [response expectedContentLength];
[self.delegate downloadStarted];
APLog(@"expected download size: %i", _expectedDownloadSize);
} else {
APLog(@"unhandled status code %i", statusCode);
if ([self.delegate respondsToSelector:@selector(downloadFailedWithErrorDescription:)])
[self.delegate downloadFailedWithErrorDescription:[NSString stringWithFormat:@"Download failed with HTTP code %i", statusCode]];
}
}
......@@ -68,8 +72,8 @@
if (!fileHandle) {
APLog(@"file creation failed, no data was saved");
if ([self.delegate respondsToSelector:@selector(downloadFailedWithError:)])
[self.delegate downloadFailedWithError:nil];
if ([self.delegate respondsToSelector:@selector(downloadFailedWithErrorDescription:)])
[self.delegate downloadFailedWithErrorDescription:@"File creation failed"];
return;
}
}
......@@ -105,8 +109,8 @@
_downloadInProgress = NO;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if ([self.delegate respondsToSelector:@selector(downloadFailedWithError:)])
[self.delegate downloadFailedWithError:error];
if ([self.delegate respondsToSelector:@selector(downloadFailedWithErrorDescription:)])
[self.delegate downloadFailedWithErrorDescription:error.description];
[self.delegate downloadEnded];
}
......@@ -114,6 +118,10 @@
- (void)cancelDownload
{
[_urlConnection cancel];
if ([self.delegate respondsToSelector:@selector(downloadFailedWithErrorDescription:)])
[self.delegate downloadFailedWithErrorDescription:@"Download canceled by user"];
[self.delegate downloadEnded];
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment