diff --git a/src/FilterLists.Agent/Features/Urls/ValidateUrls.cs b/src/FilterLists.Agent/Features/Urls/ValidateUrls.cs index 743ee67b1..f40913985 100644 --- a/src/FilterLists.Agent/Features/Urls/ValidateUrls.cs +++ b/src/FilterLists.Agent/Features/Urls/ValidateUrls.cs @@ -8,6 +8,7 @@ using FilterLists.Agent.Features.Urls.Models.ValidationResults; using FilterLists.Agent.Infrastructure.Clients; using MediatR; +using Microsoft.Extensions.Logging; namespace FilterLists.Agent.Features.Urls { @@ -27,10 +28,12 @@ public class Handler : IRequestHandler> { private const int MaxDegreeOfParallelism = 5; private readonly HttpClient _httpClient; + private readonly ILogger _logger; - public Handler(AgentHttpClient agentHttpClient) + public Handler(AgentHttpClient agentHttpClient, ILogger logger) { _httpClient = agentHttpClient.Client; + _logger = logger; } public async Task> Handle(Command request, CancellationToken cancellationToken) @@ -68,16 +71,26 @@ private TransformBlock BuildValidator(CancellationToke if (response.IsSuccessStatusCode) return result; result.SetBroken(); + _logger.LogError( + $"Url validation for ({u.AbsoluteUri}) failed with status code: {response.StatusCode}."); return result; } - catch (HttpRequestException) + catch (HttpRequestException ex) { result.SetBroken(); + _logger.LogError($"Url validation for ({u.AbsoluteUri}) failed.", ex); return result; } - catch (TaskCanceledException) + catch (TaskCanceledException ex) { result.SetBroken(); + _logger.LogError($"Url validation for ({u.AbsoluteUri}) failed.", ex); + return result; + } + catch (InvalidOperationException ex) + { + result.SetBroken(); + _logger.LogError($"Url validation for ({u.AbsoluteUri}) failed.", ex); return result; } }, @@ -91,14 +104,25 @@ private async Task IsHttpsSupported(Uri url, CancellationToken cancellatio try { var response = await _httpClient.GetAsync(httpsUrl, cancellationToken); + if (response.IsSuccessStatusCode) + return true; + _logger.LogError( + $"IsHttpsSupported({httpsUrl.AbsoluteUri}) failed with status code: {response.StatusCode}."); return response.IsSuccessStatusCode; } - catch (HttpRequestException) + catch (HttpRequestException ex) { + _logger.LogError($"IsHttpsSupported({httpsUrl.AbsoluteUri}) failed.", ex); return false; } - catch (TaskCanceledException) + catch (TaskCanceledException ex) { + _logger.LogError($"IsHttpsSupported({httpsUrl.AbsoluteUri}) failed.", ex); + return false; + } + catch (InvalidOperationException ex) + { + _logger.LogError($"IsHttpsSupported({httpsUrl.AbsoluteUri}) failed.", ex); return false; } }