Skip to content

Commit

Permalink
Add check for http statusCode on file downloads (#2073)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Shapiro
  • Loading branch information
zorgiepoo committed Jan 22, 2022
1 parent fa9bfc1 commit 6bed29c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Downloader/SPUDownloader.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,16 @@ - (void)cleanup:(void (^)(void))completionHandler
});
}

- (void)URLSession:(NSURLSession *)__unused session downloadTask:(NSURLSessionDownloadTask *)__unused downloadTask didFinishDownloadingToURL:(NSURL *)location
- (void)URLSession:(NSURLSession *)__unused session downloadTask:(NSURLSessionDownloadTask *) downloadTask didFinishDownloadingToURL:(NSURL *)location
{
if (self.mode == SPUDownloadModeTemporary)
NSInteger statusCode = [downloadTask.response isKindOfClass:[NSHTTPURLResponse class]] ? ((NSHTTPURLResponse *)downloadTask.response).statusCode : 200;
if ((statusCode < 200) || (statusCode >= 400))
{
NSString *message = [NSString stringWithFormat:@"A network error occurred while downloading the update. %@ (%ld)", [NSHTTPURLResponse localizedStringForStatusCode:statusCode], (long)statusCode];
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:@{ NSLocalizedDescriptionKey: message }];
[self.delegate downloaderDidFailWithError:error];
}
else if (self.mode == SPUDownloadModeTemporary)
{
self.downloadFilename = location.path;
[self downloadDidFinish]; // file is already in a system temp dir
Expand Down

0 comments on commit 6bed29c

Please sign in to comment.