diff roundup/rest.py @ 5593:344b6a87dac6 REST-rebased

Added support to print error .. to output when server DEBUG_MODE is true, some coding improvements committer: Ralf Schlatterbeck <rsc@runtux.com>
author Chau Nguyen <dangchau1991@yahoo.com>
date Wed, 30 Jan 2019 10:26:35 +0100
parents a25d79e874cb
children 864cf6cb5790
line wrap: on
line diff
--- a/roundup/rest.py	Wed Jan 30 10:26:35 2019 +0100
+++ b/roundup/rest.py	Wed Jan 30 10:26:35 2019 +0100
@@ -43,12 +43,14 @@
         except:
             exc, val, tb = sys.exc_info()
             code = 400
-            # if self.DEBUG_MODE in roundup_server
-            # else data = 'An error occurred. Please check...',
-            data = val
-
+            ts = time.ctime()
+            if self.client.request.DEBUG_MODE:
+                data = val
+            else:
+                data = '%s: An error occurred. Please check the server log' \
+                       ' for more information.' % ts
             # out to the logfile
-            print 'EXCEPTION AT', time.ctime()
+            print 'EXCEPTION AT', ts
             traceback.print_exc()
 
         # decorate it
@@ -71,6 +73,8 @@
 class RestfulInstance(object):
     """The RestfulInstance performs REST request from the client"""
 
+    __default_patch_op = "replace"  # default operator for PATCH method
+
     def __init__(self, client, db):
         self.client = client
         self.db = db
@@ -621,7 +625,7 @@
         try:
             op = input['op'].value.lower()
         except KeyError:
-            op = "replace"
+            op = self.__default_patch_op
         class_obj = self.db.getclass(class_name)
 
         props = self.props_from_args(class_obj, input.value, item_id)
@@ -689,8 +693,7 @@
         try:
             op = input['op'].value.lower()
         except KeyError:
-            op = "replace"
-        class_obj = self.db.getclass(class_name)
+            op = self.__default_patch_op
 
         if not self.db.security.hasPermission(
             'Edit', self.db.getuid(), class_name, attr_name, item_id
@@ -818,7 +821,7 @@
         )
         try:
             class_name, item_id = hyperdb.splitDesignator(resource_uri)
-        except hyperdb.DesignatorError, msg:
+        except hyperdb.DesignatorError:
             class_name = resource_uri
             item_id = None
 

Roundup Issue Tracker: http://roundup-tracker.org/