Error Management in Flutter

remotes/origin/database-api-implementation
Dorian HODIN 2 years ago committed by felixmielcarek
parent 5984cfbec0
commit e172d69c3a

@ -36,8 +36,18 @@ class Location {
"id": actualUser, "id": actualUser,
}); });
var data = jsonDecode(response.body); var data = jsonDecode(response.body);
data.forEach((s)=> spot.putIfAbsent(s['user'], () => s['music'])); if (data.runtimeType==String) {
return spot; if (data=="Failed to connect to MySQL, connection timeout"){
return Future.error("Failed to connect to MySQL, connection timeout");
}else if (data=="The POST didn't return any values"){
return Future.error("POST method failed");
}else{
return Future.error("Can't find current user in the database");
}
}else {
data.forEach((s) => spot.putIfAbsent(s['user'], () => s['music']));
return spot;
}
} }
} }

@ -16,7 +16,7 @@ function meters($lat1, $lng1, $lat2, $lng2): float
$connect=""; //Else PHP send an error, "connect don't exist", but that work anyway, this is just to remove a fake error $connect=""; //Else PHP send an error, "connect don't exist", but that work anyway, this is just to remove a fake error
$res=include "config.php"; //$res get the result of the calling of "config.php" $res=include "config.php"; //$res get the result of the calling of "config.php"
if ($res != 1){ //Check if config.php work if ($res != 1){ //Check if config.php work
print (json_encode("Failed to connect to MySQL")); //Return a json string, so the dart script can interpret the error print (json_encode("Failed to connect to MySQL, connection timeout")); //Return a json string, so the dart script can interpret the error
} }
if (!empty($_POST)) { if (!empty($_POST)) {
$id = $_POST['id']; //Get the result of the POST method in id $id = $_POST['id']; //Get the result of the POST method in id

@ -2,7 +2,7 @@
$connect=""; //Else PHP send an error, "connect don't exist", but that work anyway, this is just to remove a fake error $connect=""; //Else PHP send an error, "connect don't exist", but that work anyway, this is just to remove a fake error
$res=include "config.php"; //$res get the result of the calling of "config.php" $res=include "config.php"; //$res get the result of the calling of "config.php"
if ($res != 1){ //Check if config.php work if ($res != 1){ //Check if config.php work
print (json_encode("Failed to connect to MySQL")); //Return a json string, so the dart script can interpret the error print (json_encode("Failed to connect to MySQL, connection timeout")); //Return a json string, so the dart script can interpret the error
} }
if (!empty($_POST)) { //Check if the method POST return something if (!empty($_POST)) { //Check if the method POST return something
$id = mysqli_real_escape_string($connect, $_POST['id']); //Get the result of POST method $id = mysqli_real_escape_string($connect, $_POST['id']); //Get the result of POST method

Loading…
Cancel
Save