-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
Shouldn't this be handled by a 404 or just making it more graceful. Was also wondering whether the code should look like this:
class HookboxWebAPI(object):
logger = logging.getLogger('HookboxRest')
def __init__(self, api):
self.api = api
def __call__(self, environ, start_response):
path = environ['PATH_INFO']
handler = getattr(self, 'render_' + path[1:], None)
if not handler:
start_response('404 Not Found', ())
return "Not Found"
if not self.api.is_enabled():
start_response('200 Ok', ())
return json.dumps([False, { 'msg': "Rest api is disabled by configuration. (Please supply --rest-secret/-r option at start)" }])
try:
form = get_form(environ)
secret = form.pop('security_token', None)
self.api.authorize(secret)
return handler(form, start_response)
except ExpectedException, e:
start_response('200 Ok', [])
self.logger.warn('REST Error: %s' % e)
return json.dumps([False, {'msg': str(e) }])
except Exception, e:
self.logger.warn('REST Error: %s', path, exc_info=True)
start_response('500 Internal server error', [])
return json.dumps([False, {'msg': str(e) }])
Thanks.
Metadata
Metadata
Assignees
Labels
No labels