log non-sucessful HTTP status codes while downloading lists

This commit is contained in:
Collin M. Barrett 2019-07-02 10:37:33 -05:00
parent ac05b0c22a
commit ea1909a551
3 changed files with 22 additions and 4 deletions

View file

@ -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<Command>
{
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<Handler> _logger;
public Handler(AgentHttpClient agentHttpClient)
public Handler(AgentHttpClient agentHttpClient, ILogger<Handler> 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}");
}
}
}

View file

@ -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<Command>
{
private const string RepoDirectory = "archives";
private readonly HttpClient _httpClient;
private readonly ILogger<Handler> _logger;
public Handler(AgentHttpClient agentHttpClient)
public Handler(AgentHttpClient agentHttpClient, ILogger<Handler> 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}");
}
}
}

View file

@ -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<Command>
{
private const string RepoDirectory = "archives";
private readonly HttpClient _httpClient;
private readonly ILogger<Handler> _logger;
public Handler(AgentHttpClient agentHttpClient)
public Handler(AgentHttpClient agentHttpClient, ILogger<Handler> 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}");
}
}
}