Skip to content

Commit a802717

Browse files
committed
Added exception Handling
committer: Ralf Schlatterbeck <[email protected]>
1 parent 61bc2e6 commit a802717

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

roundup/rest.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77

88
import json
99
import pprint
10+
import sys
11+
import time
12+
import traceback
1013
from roundup import hyperdb
1114
from roundup.exceptions import *
1215
from roundup import xmlrpc
1316

17+
1418
def props_from_args(db, cl, args, itemid=None):
1519
props = {}
1620
for arg in args:
@@ -36,6 +40,7 @@ def props_from_args(db, cl, args, itemid=None):
3640

3741
return props
3842

43+
3944
class RestfulInstance(object):
4045
"""Dummy Handler for REST
4146
"""
@@ -183,16 +188,28 @@ def dispatch(self, method, uri, input):
183188
class_name, item_id = hyperdb.splitDesignator(resource_uri)
184189
output = getattr(self, "%s_element" % method.lower())(
185190
class_name, item_id, input)
186-
except hyperdb.DesignatorError:
187-
raise NotImplementedError('Invalid URI')
188-
except AttributeError:
189-
raise NotImplementedError('Method is invalid')
191+
except (hyperdb.DesignatorError, UsageError, Unauthorised), msg:
192+
output = {'status': 'error', 'msg': msg}
193+
except (AttributeError, Reject):
194+
output = {'status': 'error', 'msg': 'Method is not allowed'}
195+
except NotImplementedError:
196+
output = {'status': 'error', 'msg': 'Method is under development'}
197+
except:
198+
# if self.DEBUG_MODE in roundup_server
199+
# else msg = 'An error occurred. Please check...',
200+
exc, val, tb = sys.exc_info()
201+
output = {'status': 'error', 'msg': val}
202+
203+
# out to the logfile, it would be nice if the server do it for me
204+
print 'EXCEPTION AT', time.ctime()
205+
traceback.print_exc()
190206
finally:
191207
output = RoundupJSONEncoder().encode(output)
192208

193209
print "Length: %s - Content(50 char): %s" % (len(output), output[:50])
194210
return output
195211

212+
196213
class RoundupJSONEncoder(json.JSONEncoder):
197214
def default(self, obj):
198215
try:

0 commit comments

Comments
 (0)