From c28a69e2eb758b70f8631b2cf5c63d12093a1fc5 Mon Sep 17 00:00:00 2001 From: Guillaume Mazoyer Date: Wed, 11 Jun 2014 09:56:00 +0200 Subject: Handle error more properly. Exception are forwarded up to be able to inform the user about it. --- execute.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'execute.php') diff --git a/execute.php b/execute.php index dd24a6c..6a5cd45 100644 --- a/execute.php +++ b/execute.php @@ -68,10 +68,22 @@ if (isset($_POST['query']) && !empty($_POST['query']) && // Do the processing $router = Router::instance($hostname, $_SERVER['REMOTE_ADDR']); - $data = $router->send_command($query, $parameters); - // Display the result of the command - print process_output($data); + try { + $output = $router->send_command($query, $parameters); + } catch (Exception $e) { + $error = $e->getMessage(); + } + + if (isset($output)) { + // Display the result of the command + $data = array('result' => process_output($output)); + } else { + // Display the error + $data = array('error' => $error); + } + + print json_encode($data); } // End of execute.php -- cgit v1.2.3