Added AirtimeDatabaseException class to handle error cases in database-setup

This commit is contained in:
Duncan Sommerville 2014-12-11 12:57:21 -05:00
parent e338598a30
commit 5802603566
1 changed files with 26 additions and 1 deletions

View File

@ -61,6 +61,22 @@ abstract class Setup {
}
class AirtimeDatabaseException extends Exception {
protected $message = "Unknown Airtime database exception";
protected $errors = array();
public function __construct($message = null, $errors = array(), $code = 0, Exception $previous = null) {
parent::__construct($message, $code, $previous);
$this->errors = $errors;
}
public function getErrorFields() {
return $this->errors;
}
}
// Import Setup subclasses
require_once('database-setup.php');
@ -74,7 +90,16 @@ if (!file_exists("/etc/airtime/airtime.conf")) {
if (isset($_GET["obj"]) && $objType = $_GET["obj"]) {
$obj = new $objType($_POST);
if ($obj instanceof Setup) {
echo json_encode($obj->runSetup());
try {
$response = $obj->runSetup();
} catch(AirtimeDatabaseException $e) {
$response = array(
"message" => $e->getMessage(),
"errors" => $e->getErrorFields(),
);
}
echo json_encode($response);
}
}
}