From 0bf807f01ec7bf5947e6518b254542e885f8c8dd Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Tue, 2 Jul 2019 09:17:38 -0500 Subject: [PATCH] limit scope of try block --- .../Features/Lists/DownloadLists.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/FilterLists.Agent/Features/Lists/DownloadLists.cs b/src/FilterLists.Agent/Features/Lists/DownloadLists.cs index 5ce094ac2..931c5253b 100644 --- a/src/FilterLists.Agent/Features/Lists/DownloadLists.cs +++ b/src/FilterLists.Agent/Features/Lists/DownloadLists.cs @@ -82,26 +82,26 @@ private ActionBlock BuildDownloader(CancellationToken cancellationToke async l => { var errorMessage = $"Error downloading list {l.Id} from {l.ViewUrl}."; - try + var extension = l.ViewUrl.GetExtension(); + if (CommandsByExtension.ContainsKey(extension)) { - var extension = l.ViewUrl.GetExtension(); - if (CommandsByExtension.ContainsKey(extension)) + var command = CommandsByExtension[extension].Invoke(l); + try { - var command = CommandsByExtension[extension].Invoke(l); await _mediator.Send(command, cancellationToken); } - else + catch (HttpRequestException ex) { - _logger.LogError($"The file extension of list {l.Id} from {l.ViewUrl} is not supported."); + _logger.LogError(ex, errorMessage); + } + catch (TaskCanceledException ex) + { + _logger.LogError(ex, errorMessage); } } - catch (HttpRequestException ex) + else { - _logger.LogError(ex, errorMessage); - } - catch (TaskCanceledException ex) - { - _logger.LogError(ex, errorMessage); + _logger.LogError($"The file extension of list {l.Id} from {l.ViewUrl} is not supported."); } }, new ExecutionDataflowBlockOptions {MaxDegreeOfParallelism = MaxDegreeOfParallelism}