@@ -101,45 +101,43 @@ ILogger<OpenMeteoWeatherLookupService> logger
101101 // Determine which API to call (forecast vs. archive)
102102 var daysDiff = ( int ) ( DateTime . UtcNow . Date - dateTimeUtc . Date ) . TotalDays ;
103103 var isHistorical = daysDiff > 92 ;
104- var endpoint = isHistorical
105- ? "https://archive-api.open-meteo.com/v1/archive"
106- : "https://api.open-meteo.com/v1/forecast" ;
104+ var clientName = isHistorical ? "OpenMeteoArchive" : "OpenMeteoForecast" ;
105+ var requestPath = isHistorical ? "/v1/archive" : "/v1/forecast" ;
107106
108107 var apiKey = configuration [ "WeatherLookup:ApiKey" ] ;
109108 var apiKeyParam = string . IsNullOrWhiteSpace ( apiKey )
110109 ? string . Empty
111110 : $ "&apikey={ Uri . EscapeDataString ( apiKey ) } ";
112111
113112 // Build query parameters
114- var pastDaysParam = isHistorical ? "" : $ "&past_days= { Math . Min ( daysDiff + 1 , 92 ) } " ;
113+ // Note: past_days is mutually exclusive with start_date/end_date on the Open-Meteo API.
115114 var queryParams =
116115 $ "?latitude={ Uri . EscapeDataString ( latitude . ToString ( CultureInfo . InvariantCulture ) ) } "
117116 + $ "&longitude={ Uri . EscapeDataString ( longitude . ToString ( CultureInfo . InvariantCulture ) ) } "
118117 + $ "&start_date={ dateTimeUtc . Date : yyyy-MM-dd} "
119118 + $ "&end_date={ dateTimeUtc . Date : yyyy-MM-dd} "
120- + $ "{ pastDaysParam } "
121119 + "&hourly=temperature_2m,wind_speed_10m,wind_direction_10m,relative_humidity_2m,cloud_cover,precipitation,weather_code"
122120 + "&temperature_unit=fahrenheit"
123121 + "&wind_speed_unit=mph"
124122 + "&timezone=auto"
125123 + apiKeyParam ;
126-
127124 try
128125 {
129- var client = httpClientFactory . CreateClient ( "OpenMeteo" ) ;
126+ var client = httpClientFactory . CreateClient ( clientName ) ;
130127 using var response = await client . GetAsync (
131- $ "{ endpoint } { queryParams } ",
128+ $ "{ requestPath } { queryParams } ",
132129 cancellationToken
133130 ) ;
134131
135132 if ( ! response . IsSuccessStatusCode )
136133 {
137134 logger . LogWarning (
138- "Open-Meteo lookup failed for rounded {LatitudeRounded},{LongitudeRounded} at {UtcHour} with status {StatusCode}" ,
135+ "Open-Meteo lookup failed for rounded {LatitudeRounded},{LongitudeRounded} at {UtcHour} with status {StatusCode}: {ResponseContent} " ,
139136 latRounded ,
140137 lonRounded ,
141138 dateTimeUtc ,
142- response . StatusCode
139+ response . StatusCode ,
140+ await response . Content . ReadAsStringAsync ( cancellationToken )
143141 ) ;
144142
145143 // Cache failure for short period to avoid hammering API
0 commit comments