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] 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

