Skip to content

Commit a86f857

Browse files
committed
Added support to print error
.. to output when server DEBUG_MODE is true, some coding improvements committer: Ralf Schlatterbeck <[email protected]>
1 parent f4ef864 commit a86f857

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

roundup/rest.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ def format_object(self, *args, **kwargs):
4343
except:
4444
exc, val, tb = sys.exc_info()
4545
code = 400
46-
# if self.DEBUG_MODE in roundup_server
47-
# else data = 'An error occurred. Please check...',
48-
data = val
49-
46+
ts = time.ctime()
47+
if self.client.request.DEBUG_MODE:
48+
data = val
49+
else:
50+
data = '%s: An error occurred. Please check the server log' \
51+
' for more information.' % ts
5052
# out to the logfile
51-
print 'EXCEPTION AT', time.ctime()
53+
print 'EXCEPTION AT', ts
5254
traceback.print_exc()
5355

5456
# decorate it
@@ -71,6 +73,8 @@ def format_object(self, *args, **kwargs):
7173
class RestfulInstance(object):
7274
"""The RestfulInstance performs REST request from the client"""
7375

76+
__default_patch_op = "replace" # default operator for PATCH method
77+
7478
def __init__(self, client, db):
7579
self.client = client
7680
self.db = db
@@ -621,7 +625,7 @@ def patch_element(self, class_name, item_id, input):
621625
try:
622626
op = input['op'].value.lower()
623627
except KeyError:
624-
op = "replace"
628+
op = self.__default_patch_op
625629
class_obj = self.db.getclass(class_name)
626630

627631
props = self.props_from_args(class_obj, input.value, item_id)
@@ -689,8 +693,7 @@ def patch_attribute(self, class_name, item_id, attr_name, input):
689693
try:
690694
op = input['op'].value.lower()
691695
except KeyError:
692-
op = "replace"
693-
class_obj = self.db.getclass(class_name)
696+
op = self.__default_patch_op
694697

695698
if not self.db.security.hasPermission(
696699
'Edit', self.db.getuid(), class_name, attr_name, item_id
@@ -818,7 +821,7 @@ def dispatch(self, method, uri, input):
818821
)
819822
try:
820823
class_name, item_id = hyperdb.splitDesignator(resource_uri)
821-
except hyperdb.DesignatorError, msg:
824+
except hyperdb.DesignatorError:
822825
class_name = resource_uri
823826
item_id = None
824827

0 commit comments

Comments
 (0)