diff rhodecode/controllers/api/__init__.py @ 1708:fee9895fa46e beta

changed API to match fully JSON-RPC specs
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 21 Nov 2011 03:08:09 +0200
parents 60249224be04
children 631caf880b87
line wrap: on
line diff
--- a/rhodecode/controllers/api/__init__.py	Mon Nov 21 02:53:17 2011 +0200
+++ b/rhodecode/controllers/api/__init__.py	Mon Nov 21 03:08:09 2011 +0200
@@ -50,6 +50,7 @@
 
     def __init__(self, message):
         self.message = message
+        super(JSONRPCError, self).__init__()
 
     def __str__(self):
         return str(self.message)
@@ -60,7 +61,7 @@
     Generate a Response object with a JSON-RPC error body
     """
     from pylons.controllers.util import Response
-    resp = Response(body=json.dumps(dict(result=None, error=message)),
+    resp = Response(body=json.dumps(dict(id=None, result=None, error=message)),
                     status=code,
                     content_type='application/json')
     return resp
@@ -117,6 +118,7 @@
         # check AUTH based on API KEY
         try:
             self._req_api_key = json_body['api_key']
+            self._req_id = json_body['id']
             self._req_method = json_body['method']
             self._req_params = json_body['args']
             log.debug('method: %s, params: %s',
@@ -220,7 +222,8 @@
         if self._error is not None:
             raw_response = None
 
-        response = dict(result=raw_response, error=self._error)
+        response = dict(id=self._req_id, result=raw_response,
+                        error=self._error)
 
         try:
             return json.dumps(response)