diff --git a/src/WinSW.Core/Download.cs b/src/WinSW.Core/Download.cs index f1eb799..fa6c8a7 100644 --- a/src/WinSW.Core/Download.cs +++ b/src/WinSW.Core/Download.cs @@ -193,10 +193,14 @@ namespace WinSW if (supportsIfModifiedSince && ((HttpWebResponse?)e.Response)?.StatusCode == HttpStatusCode.NotModified) { Logger.Info($"Skipped downloading unmodified resource '{this.From}'"); + return; } - else + + string errorMessage = $"Failed to download {this.From} to {this.To}"; + Logger.Error(errorMessage, e); + if (this.FailOnError) { - throw; + throw new IOException(errorMessage, e); } } } diff --git a/src/WinSW.Core/WrapperService.cs b/src/WinSW.Core/WrapperService.cs index 3bb8076..7a97721 100644 --- a/src/WinSW.Core/WrapperService.cs +++ b/src/WinSW.Core/WrapperService.cs @@ -272,32 +272,7 @@ namespace WinSW tasks[i] = download.PerformAsync(); } - try - { - Task.WaitAll(tasks); - } - catch (AggregateException e) - { - var exceptions = new List(e.InnerExceptions.Count); - for (int i = 0; i < tasks.Length; i++) - { - if (tasks[i].IsFaulted) - { - var download = downloads[i]; - string errorMessage = $"Failed to download {download.From} to {download.To}"; - var exception = tasks[i].Exception!; - Log.Error(errorMessage, exception); - - // TODO: move this code into the download logic - if (download.FailOnError) - { - exceptions.Add(new IOException(errorMessage, exception)); - } - } - } - - throw new AggregateException(exceptions); - } + Task.WaitAll(tasks); var sharedDirectories = this.config.SharedDirectories; if (sharedDirectories.Count > 0) diff --git a/src/WinSW.Tests/DownloadTests.cs b/src/WinSW.Tests/DownloadTests.cs index 880370e..fdeac77 100644 --- a/src/WinSW.Tests/DownloadTests.cs +++ b/src/WinSW.Tests/DownloadTests.cs @@ -210,10 +210,11 @@ namespace WinSW.Tests await this.TestClientServerAsync( async (source, dest) => { - var exception = await Assert.ThrowsAsync( - async () => await new Download(source, dest).PerformAsync()); + var exception = await Assert.ThrowsAsync( + async () => await new Download(source, dest, true).PerformAsync()); - Assert.Equal(WebExceptionStatus.ProtocolError, exception.Status); + var inner = Assert.IsType(exception.InnerException); + Assert.Equal(WebExceptionStatus.ProtocolError, inner.Status); }, context => {