File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
samples/QuickstartWeatherServer/Tools Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -42,8 +42,11 @@ public static async Task<string> GetForecast(
4242 [ Description ( "Longitude of the location." ) ] double longitude )
4343 {
4444 using var jsonDocument = await client . ReadJsonDocumentAsync ( $ "/points/{ latitude } ,{ longitude } ") ;
45- var jsonElement = jsonDocument . RootElement ;
46- var periods = jsonElement . GetProperty ( "properties" ) . GetProperty ( "periods" ) . EnumerateArray ( ) ;
45+ var forecastUrl = jsonDocument . RootElement . GetProperty ( "properties" ) . GetProperty ( "forecast" ) . GetString ( )
46+ ?? throw new Exception ( $ "No forecast URL provided by { client . BaseAddress } points/{ latitude } ,{ longitude } ") ;
47+
48+ using var forecastDocument = await client . ReadJsonDocumentAsync ( forecastUrl ) ;
49+ var periods = forecastDocument . RootElement . GetProperty ( "properties" ) . GetProperty ( "periods" ) . EnumerateArray ( ) ;
4750
4851 return string . Join ( "\n ---\n " , periods . Select ( period => $ """
4952 { period . GetProperty ( "name" ) . GetString ( ) }
@@ -52,4 +55,4 @@ public static async Task<string> GetForecast(
5255 Forecast: { period . GetProperty ( "detailedForecast" ) . GetString ( ) }
5356 """ ) ) ;
5457 }
55- }
58+ }
You can’t perform that action at this time.
0 commit comments