소스 검색

VLCHTTPFileDownloader: improve error reporting

Felix Paul Kühne 12 년 전
부모
커밋
1b1116c90e
2개의 변경된 파일13개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 1
      AspenProject/VLCHTTPFileDownloader.h
  2. 12 4
      AspenProject/VLCHTTPFileDownloader.m

+ 1 - 1
AspenProject/VLCHTTPFileDownloader.h

@@ -14,7 +14,7 @@
 - (void)downloadEnded;
 
 @optional
-- (void)downloadFailedWithError:(NSError *)error;
+- (void)downloadFailedWithErrorDescription:(NSString *)description;
 - (void)progressUpdatedTo:(CGFloat)percentage;
 
 @end

+ 12 - 4
AspenProject/VLCHTTPFileDownloader.m

@@ -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