From ea1909a551e37106b064d391d90fbd0e4974dfcc Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Tue, 2 Jul 2019 10:37:33 -0500 Subject: [PATCH] log non-sucessful HTTP status codes while downloading lists --- .../Features/Lists/DownloadRawText.cs | 10 ++++++++-- .../Features/Lists/DownloadSevenZip.cs | 8 +++++++- src/FilterLists.Agent/Features/Lists/DownloadZip.cs | 8 +++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/FilterLists.Agent/Features/Lists/DownloadRawText.cs b/src/FilterLists.Agent/Features/Lists/DownloadRawText.cs index d98967558..3a83aeef8 100644 --- a/src/FilterLists.Agent/Features/Lists/DownloadRawText.cs +++ b/src/FilterLists.Agent/Features/Lists/DownloadRawText.cs @@ -7,6 +7,7 @@ using FilterLists.Agent.Extensions; using FilterLists.Agent.Infrastructure.Clients; using MediatR; +using Microsoft.Extensions.Logging; namespace FilterLists.Agent.Features.Lists { @@ -25,12 +26,14 @@ public Command(ListInfo listInfo) public class Handler : AsyncRequestHandler { private const string RepoDirectory = "archives"; - private readonly string[] _extensionsToRewrite = { "", ".aspx", ".p2p", ".php" }; + private readonly string[] _extensionsToRewrite = {"", ".aspx", ".p2p", ".php"}; private readonly HttpClient _httpClient; + private readonly ILogger _logger; - public Handler(AgentHttpClient agentHttpClient) + public Handler(AgentHttpClient agentHttpClient, ILogger logger) { _httpClient = agentHttpClient.Client; + _logger = logger; } protected override async Task Handle(Command request, CancellationToken cancellationToken) @@ -46,6 +49,9 @@ protected override async Task Handle(Command request, CancellationToken cancella { await input.CopyToAsync(output, cancellationToken); } + else + _logger.LogError( + $"Error downloading list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}. {response.StatusCode}"); } } } diff --git a/src/FilterLists.Agent/Features/Lists/DownloadSevenZip.cs b/src/FilterLists.Agent/Features/Lists/DownloadSevenZip.cs index 519d4cd0a..f5358dcde 100644 --- a/src/FilterLists.Agent/Features/Lists/DownloadSevenZip.cs +++ b/src/FilterLists.Agent/Features/Lists/DownloadSevenZip.cs @@ -5,6 +5,7 @@ using FilterLists.Agent.Core.Entities; using FilterLists.Agent.Infrastructure.Clients; using MediatR; +using Microsoft.Extensions.Logging; using SharpCompress.Archives; using SharpCompress.Archives.SevenZip; using SharpCompress.Common; @@ -27,10 +28,12 @@ public class Handler : AsyncRequestHandler { private const string RepoDirectory = "archives"; private readonly HttpClient _httpClient; + private readonly ILogger _logger; - public Handler(AgentHttpClient agentHttpClient) + public Handler(AgentHttpClient agentHttpClient, ILogger logger) { _httpClient = agentHttpClient.Client; + _logger = logger; } protected override async Task Handle(Command request, CancellationToken cancellationToken) @@ -47,6 +50,9 @@ protected override async Task Handle(Command request, CancellationToken cancella entry.WriteToDirectory(destinationDirectoryPath, new ExtractionOptions {ExtractFullPath = true, Overwrite = true}); } + else + _logger.LogError( + $"Error downloading list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}. {response.StatusCode}"); } } } diff --git a/src/FilterLists.Agent/Features/Lists/DownloadZip.cs b/src/FilterLists.Agent/Features/Lists/DownloadZip.cs index 25431eef1..e9e982818 100644 --- a/src/FilterLists.Agent/Features/Lists/DownloadZip.cs +++ b/src/FilterLists.Agent/Features/Lists/DownloadZip.cs @@ -5,6 +5,7 @@ using FilterLists.Agent.Core.Entities; using FilterLists.Agent.Infrastructure.Clients; using MediatR; +using Microsoft.Extensions.Logging; using SharpCompress.Common; using SharpCompress.Readers; @@ -26,10 +27,12 @@ public class Handler : AsyncRequestHandler { private const string RepoDirectory = "archives"; private readonly HttpClient _httpClient; + private readonly ILogger _logger; - public Handler(AgentHttpClient agentHttpClient) + public Handler(AgentHttpClient agentHttpClient, ILogger logger) { _httpClient = agentHttpClient.Client; + _logger = logger; } protected override async Task Handle(Command request, CancellationToken cancellationToken) @@ -46,6 +49,9 @@ protected override async Task Handle(Command request, CancellationToken cancella reader.WriteEntryToDirectory(destinationDirectoryPath, new ExtractionOptions {ExtractFullPath = true, Overwrite = true}); } + else + _logger.LogError( + $"Error downloading list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}. {response.StatusCode}"); } } }