From 115493a0a5078ea7c0f3808b09ebddd134cba0e4 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Fri, 28 Jun 2019 18:10:24 -0500 Subject: [PATCH] fix try/catch to catch HttpRequestExceptions --- .../DownloadTxt.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/FilterLists.Agent/ListArchiver/DownloadRequestsByFileExtension/DownloadTxt.cs b/src/FilterLists.Agent/ListArchiver/DownloadRequestsByFileExtension/DownloadTxt.cs index 81fe28549..550210e76 100644 --- a/src/FilterLists.Agent/ListArchiver/DownloadRequestsByFileExtension/DownloadTxt.cs +++ b/src/FilterLists.Agent/ListArchiver/DownloadRequestsByFileExtension/DownloadTxt.cs @@ -33,23 +33,23 @@ public Handler(HttpClient httpClient, ILogger 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}."); } } }