mirror of https://github.com/winsw/winsw
Fix download exceptions when ignoring errors (#854)
parent
20846238ea
commit
9bfc034807
|
@ -231,10 +231,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,10 +215,11 @@ namespace winswTests
|
|||
await this.TestClientServerAsync(
|
||||
async (source, dest) =>
|
||||
{
|
||||
var exception = await AsyncAssert.ThrowsAsync<WebException>(
|
||||
async () => await new Download(source, dest).PerformAsync());
|
||||
var exception = await AsyncAssert.ThrowsAsync<IOException>(
|
||||
async () => await new Download(source, dest, true).PerformAsync());
|
||||
|
||||
Assert.That(exception.Status, Is.EqualTo(WebExceptionStatus.ProtocolError));
|
||||
var inner = (WebException)exception.InnerException;
|
||||
Assert.That(inner.Status, Is.EqualTo(WebExceptionStatus.ProtocolError));
|
||||
},
|
||||
context =>
|
||||
{
|
||||
|
|
|
@ -246,58 +246,15 @@ namespace WinSW
|
|||
tasks[i] = download.PerformAsync();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Task.WaitAll(tasks);
|
||||
}
|
||||
catch (AggregateException e)
|
||||
{
|
||||
var exceptions = new List<Exception>(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!;
|
||||
this.LogEvent($"{errorMessage}. {exception.Message}");
|
||||
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);
|
||||
}
|
||||
#else
|
||||
foreach (var download in this.config.Downloads)
|
||||
{
|
||||
string downloadMessage = $"Downloading: {download.From} to {download.To}. failOnError={download.FailOnError.ToString()}";
|
||||
this.LogEvent(downloadMessage);
|
||||
Log.Info(downloadMessage);
|
||||
try
|
||||
{
|
||||
download.Perform();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
string errorMessage = $"Failed to download {download.From} to {download.To}";
|
||||
this.LogEvent($"{errorMessage}. {e.Message}");
|
||||
Log.Error(errorMessage, e);
|
||||
|
||||
// TODO: move this code into the download logic
|
||||
if (download.FailOnError)
|
||||
{
|
||||
throw new IOException(errorMessage, e);
|
||||
}
|
||||
|
||||
// Else just keep going
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
string? startArguments = this.config.StartArguments;
|
||||
|
|
Loading…
Reference in New Issue