77
88import json
99import pprint
10+ import sys
11+ import time
12+ import traceback
1013from roundup import hyperdb
1114from roundup .exceptions import *
1215from roundup import xmlrpc
1316
17+
1418def 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+
3944class 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+
196213class RoundupJSONEncoder (json .JSONEncoder ):
197214 def default (self , obj ):
198215 try :
0 commit comments