Add the heat index as well as some error handling.

This commit is contained in:
2025-04-26 08:37:35 -07:00
parent 7ffcfee1d3
commit 6e2d293cdc
3 changed files with 76 additions and 22 deletions

View File

@ -10,26 +10,30 @@ import 'dart:convert';
Future<String> hitAPI(String url) async {
if (debug) debugPrint("DEBUG: URL is '$url'.");
http.Response response = await http.get(Uri.parse(url));
try {
http.Response response = await http.get(Uri.parse(url));
String data = "";
if (response.statusCode == 200) {
data = response.body;
var decodedData = jsonDecode(data);
//data = decodedData.toString();
//data = jsonEncode(decodedData);
if (debugVerbose) {
debugPrint("DEBUG-VERBOSE: Response data: \n\n$data\n");
}
} else {
if (debug) {
debugPrint(
"DEBUG: Response failed with code '${response.statusCode.toString()}'",
);
String data = "";
if (response.statusCode == 200) {
data = response.body;
var decodedData = jsonDecode(data);
//data = decodedData.toString();
//data = jsonEncode(decodedData);
if (debugVerbose) {
debugPrint("DEBUG-VERBOSE: Response data: \n\n$data\n");
}
} else {
if (debug) {
debugPrint(
"DEBUG: Response failed with code '${response.statusCode.toString()}'",
);
}
}
return data;
} catch (e) {
return "Sorry! It seems we have an issue: '${e.toString()}'.";
}
return data;
}
// How to guide: https://openweathermap.org/current#zip