diff --git a/Features/Routes/Services/FlightAwareRouteService.cs b/Features/Routes/Services/FlightAwareRouteService.cs index ad68b44..8363d17 100644 --- a/Features/Routes/Services/FlightAwareRouteService.cs +++ b/Features/Routes/Services/FlightAwareRouteService.cs @@ -7,7 +7,7 @@ namespace ZmaReference.Features.Routes.Services; -public partial class FlightAwareRouteService(IHttpClientFactory httpClientFactory, IOptionsMonitor appSettings, IMemoryCache cache) +public partial class FlightAwareRouteService(IHttpClientFactory httpClientFactory, IOptionsMonitor appSettings, IMemoryCache cache, ILogger logger) { public async Task FetchRoutesAsync(string departureIcao, string arrivalIcao) { @@ -18,6 +18,7 @@ public async Task FetchRoutesAsync(string departureIcao } // If not, fetch result from FlightAware + var url = MakeUrl(departureIcao, arrivalIcao); try { // Setup return object @@ -26,7 +27,7 @@ public async Task FetchRoutesAsync(string departureIcao // Open FlightAware IFR routing page var client = httpClientFactory.CreateClient(); client.DefaultRequestHeaders.UserAgent.TryParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:123.0) Gecko/20100101 Firefox/123.0"); - await using var stream = await client.GetStreamAsync(MakeUrl(departureIcao, arrivalIcao)); + await using var stream = await client.GetStreamAsync(url); var parser = new HtmlParser(); using var document = await parser.ParseDocumentAsync(stream); @@ -101,11 +102,12 @@ public async Task FetchRoutesAsync(string departureIcao } catch (HttpRequestException e) { + logger.LogError("Error fetching FlightAware url {url}: {error}", url, e); throw e; } } - private string MakeUrl(string departureIcao, string arrivalIcao) + public string MakeUrl(string departureIcao, string arrivalIcao) { return appSettings.CurrentValue.Urls.FlightAwareIfrRouteBase + "origin=" + departureIcao + "&destination=" + arrivalIcao; }