From 580260356600a9b6216114e9364a0ccb156441f1 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Thu, 11 Dec 2014 12:57:21 -0500 Subject: [PATCH] Added AirtimeDatabaseException class to handle error cases in database-setup --- airtime_mvc/public/setup/setup-functions.php | 27 +++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/public/setup/setup-functions.php b/airtime_mvc/public/setup/setup-functions.php index d7c61c050..80144305d 100644 --- a/airtime_mvc/public/setup/setup-functions.php +++ b/airtime_mvc/public/setup/setup-functions.php @@ -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); } } }