From 36cf8b5cb5b28f5ae8380b7b36e1fd4fac8caf42 Mon Sep 17 00:00:00 2001 From: Hugo Wetterberg Date: Mon, 15 Sep 2008 09:06:23 +0000 Subject: [PATCH] Added exception handling to the json-rpc server git-svn-id: http://goodold.googlecode.com/svn/drupal_modules/jsonrpc_server/trunk@180 b8d441e5-9555-0410-8e75-7fea32d02d5f --- JsonRpcServer.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/JsonRpcServer.php b/JsonRpcServer.php index c8db1f8..cab30b2 100644 --- a/JsonRpcServer.php +++ b/JsonRpcServer.php @@ -140,13 +140,18 @@ public function handle() { } //Call service method - $result = services_method_call($this->method['#method'], $this->args); - if (is_array($result) && isset($result['#error']) && $result['#error'] === TRUE) { - return $this->error(JSONRPC_ERROR_INTERNAL_ERROR, $result['#message']); - } - else { - return $this->result($result); + try { + $result = services_method_call($this->method['#method'], $this->args); + if (is_array($result) && isset($result['#error']) && $result['#error'] === TRUE) { + return $this->error(JSONRPC_ERROR_INTERNAL_ERROR, $result['#message']); + } + else { + return $this->result($result); + } + } catch (Exception $e) { + return $this->error(JSONRPC_ERROR_INTERNAL_ERROR, $e->getMessage()); } + } private function array_is_assoc(&$arr) {