@@ -1056,28 +1056,30 @@ resource apiA2aRuntimeJsonRpcPolicy 'Microsoft.ApiManagement/service/apis/operat
10561056 if (string.IsNullOrWhiteSpace(city)) { city = "Seattle"; }
10571057 return city;
10581058 }' />
1059- <send-request mode="new" response-variable-name="geoResp" timeout="10 " ignore-error="true">
1059+ <send-request mode="new" response-variable-name="geoResp" timeout="15 " ignore-error="true">
10601060 <set-url>@($"https://geocoding-api.open-meteo.com/v1/search?count=1&name={System.Uri.EscapeDataString((string)context.Variables["city"])}")</set-url>
10611061 <set-method>GET</set-method>
10621062 </send-request>
10631063 <set-variable name="latlon" value='@{
10641064 var r = (IResponse)context.Variables["geoResp"];
10651065 if (r == null || r.StatusCode != 200) { return (string)null; }
1066- var body = r.Body.As<Newtonsoft.Json.Linq.JObject>();
1067- var arr = body["results"] as Newtonsoft.Json.Linq.JArray;
1068- if (arr == null || arr.Count == 0) { return (string)null; }
1069- string lat = arr[0]["latitude"].ToString(Newtonsoft.Json.Formatting.None);
1070- string lon = arr[0]["longitude"].ToString(Newtonsoft.Json.Formatting.None);
1071- string resolved = (string)arr[0]["name"];
1072- string country = (string)arr[0]["country"];
1073- return lat + "|" + lon + "|" + resolved + "|" + (country ?? "");
1066+ try {
1067+ var body = r.Body.As<Newtonsoft.Json.Linq.JObject>();
1068+ var arr = body["results"] as Newtonsoft.Json.Linq.JArray;
1069+ if (arr == null || arr.Count == 0) { return (string)null; }
1070+ string lat = arr[0]["latitude"].ToString(Newtonsoft.Json.Formatting.None);
1071+ string lon = arr[0]["longitude"].ToString(Newtonsoft.Json.Formatting.None);
1072+ string resolved = (string)arr[0]["name"];
1073+ string country = (string)arr[0]["country"];
1074+ return lat + "|" + lon + "|" + resolved + "|" + (country ?? "");
1075+ } catch { return (string)null; }
10741076 }' />
10751077 <choose>
10761078 <when condition='@(context.Variables["latlon"] == null)'>
1077- <set-variable name="reply" value='@("Sorry, I could not find a location named " + (string)context.Variables["city"] + " .")' />
1079+ <set-variable name="reply" value='@("Weather information is currently unavailable. Please try again later .")' />
10781080 </when>
10791081 <otherwise>
1080- <send-request mode="new" response-variable-name="wxResp" timeout="10 " ignore-error="true">
1082+ <send-request mode="new" response-variable-name="wxResp" timeout="15 " ignore-error="true">
10811083 <set-url>@{
10821084 var ll = ((string)context.Variables["latlon"]).Split('|');
10831085 return "https://api.open-meteo.com/v1/forecast?latitude=" + ll[0] + "&longitude=" + ll[1] + "&current=temperature_2m,weather_code,wind_speed_10m&temperature_unit=fahrenheit&wind_speed_unit=mph";
0 commit comments