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}."); } } }