From 3c48680d063e71a5476312556ce67f7bc72ca3c0 Mon Sep 17 00:00:00 2001
From: Claudiu Cristea <clau.cristea@gmail.com>
Date: Sat, 20 Aug 2011 12:11:57 +0000
Subject: [PATCH 1/2] Respond with application code on error. See http://drupal.org/node/1255006.

---
 JsonRpcServer.php |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/JsonRpcServer.php b/JsonRpcServer.php
index 65242c5..bf1d732 100644
--- a/JsonRpcServer.php
+++ b/JsonRpcServer.php
@@ -162,11 +162,16 @@ class JsonRpcServer{
     try {
       $result = services_controller_execute($this->method, $this->args);
       return $this->result($result);
-    } catch (ServicesException $e) {
-      $this->error(JSONRPC_ERROR_INTERNAL_ERROR, $e->getMessage(), $e->getData());
+    }
+    catch (ServicesException $e) {
+      $application_error = $e->getCode();
+      $error_code = empty($application_error) ? JSONRPC_ERROR_INTERNAL_ERROR : $application_error;
+      $this->error($error_code, $e->getMessage(), $e->getData());
     }
     catch (Exception $e) {
-      $this->error(JSONRPC_ERROR_INTERNAL_ERROR, $e->getMessage());
+      $application_error = $e->getCode();
+      $error_code = empty($application_error) ? JSONRPC_ERROR_INTERNAL_ERROR : $application_error;
+      $this->error($error_code, $e->getMessage(), $e->getData());
     }
   }
   
-- 
1.7.0.4


From 005da6d63b6cfd3b9eac72804f7f51af3f480cfe Mon Sep 17 00:00:00 2001
From: Claudiu Cristea <clau.cristea@gmail.com>
Date: Sat, 20 Aug 2011 13:26:13 +0000
Subject: [PATCH 2/2] Respond with application code on error. See http://drupal.org/node/1255006.

---
 JsonRpcServer.php |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/JsonRpcServer.php b/JsonRpcServer.php
index bf1d732..b794a32 100644
--- a/JsonRpcServer.php
+++ b/JsonRpcServer.php
@@ -171,7 +171,7 @@ class JsonRpcServer{
     catch (Exception $e) {
       $application_error = $e->getCode();
       $error_code = empty($application_error) ? JSONRPC_ERROR_INTERNAL_ERROR : $application_error;
-      $this->error($error_code, $e->getMessage(), $e->getData());
+      $this->error($error_code, $e->getMessage());
     }
   }
   
-- 
1.7.0.4

