Mercurial > p > roundup > code
changeset 5567:1af57f9d5bf7 REST-rebased
Added exception Handling
committer: Ralf Schlatterbeck <rsc@runtux.com>
| author | Chau Nguyen <dangchau1991@yahoo.com> |
|---|---|
| date | Wed, 30 Jan 2019 10:26:34 +0100 |
| parents | 2830793d1510 |
| children | edab9daa8015 |
| files | roundup/rest.py |
| diffstat | 1 files changed, 21 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/roundup/rest.py Wed Jan 30 10:26:34 2019 +0100 +++ b/roundup/rest.py Wed Jan 30 10:26:34 2019 +0100 @@ -7,10 +7,14 @@ import json import pprint +import sys +import time +import traceback from roundup import hyperdb from roundup.exceptions import * from roundup import xmlrpc + def props_from_args(db, cl, args, itemid=None): props = {} for arg in args: @@ -36,6 +40,7 @@ return props + class RestfulInstance(object): """Dummy Handler for REST """ @@ -183,16 +188,28 @@ class_name, item_id = hyperdb.splitDesignator(resource_uri) output = getattr(self, "%s_element" % method.lower())( class_name, item_id, input) - except hyperdb.DesignatorError: - raise NotImplementedError('Invalid URI') - except AttributeError: - raise NotImplementedError('Method is invalid') + except (hyperdb.DesignatorError, UsageError, Unauthorised), msg: + output = {'status': 'error', 'msg': msg} + except (AttributeError, Reject): + output = {'status': 'error', 'msg': 'Method is not allowed'} + except NotImplementedError: + output = {'status': 'error', 'msg': 'Method is under development'} + except: + # if self.DEBUG_MODE in roundup_server + # else msg = 'An error occurred. Please check...', + exc, val, tb = sys.exc_info() + output = {'status': 'error', 'msg': val} + + # out to the logfile, it would be nice if the server do it for me + print 'EXCEPTION AT', time.ctime() + traceback.print_exc() finally: output = RoundupJSONEncoder().encode(output) print "Length: %s - Content(50 char): %s" % (len(output), output[:50]) return output + class RoundupJSONEncoder(json.JSONEncoder): def default(self, obj): try:
