fix try/catch to catch HttpRequestExceptions

This commit is contained in:
Collin M. Barrett 2019-06-28 18:10:24 -05:00
parent a35b1e9379
commit 115493a0a5

View file

@ -33,23 +33,23 @@ public Handler(HttpClient httpClient, ILogger<Handler> logger)
protected override async Task Handle(Command request, CancellationToken cancellationToken)
{
using (var response = await _httpClient.GetAsync(request.ListInfo.ViewUrl, cancellationToken))
try
{
if (response.IsSuccessStatusCode)
try
{
using (var response = await _httpClient.GetAsync(request.ListInfo.ViewUrl, cancellationToken))
{
if (response.IsSuccessStatusCode)
using (Stream output =
File.OpenWrite(Path.Combine("archives", $"{request.ListInfo.Id}.txt")))
using (var input = await response.Content.ReadAsStreamAsync())
{
input.CopyTo(output);
}
}
catch (HttpRequestException ex)
{
_logger.LogError(ex,
$"Error downloading list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}.");
}
}
}
catch (HttpRequestException ex)
{
_logger.LogError(ex,
$"Error downloading list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}.");
}
}
}