Add the heat index as well as some error handling.
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user