2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-25 11:01:09 +00:00

Have 'bad request' errors be more informative

This commit is contained in:
Jarrod Johnson 2014-05-09 16:38:55 -04:00
parent 2863c58264
commit 542da958db
4 changed files with 39 additions and 34 deletions

2
TODO
View File

@ -31,4 +31,4 @@ KeyError: ''
a titlebar
-audit log did not show confetty activity for starting console
-read exclusive and full exclusive console access modes
-invalid attributes at create time come out as 500
-invalid attributes at create time come out as 500

View File

@ -205,6 +205,37 @@ def parse_command(command):
currchildren = None
def print_result(res):
for key in res.iterkeys():
notes = []
if res[key] is None:
attrstr = '%s=""' % key
elif type(res[key]) == list:
attrstr = '%s=%s' % (key, recurse_format(res[key]))
elif 'value' in res[key] and res[key]['value'] is not None:
attrstr = '%s="%s"' % (key, res[key]['value'])
elif 'value' in res[key] and res[key]['value'] is None:
attrstr = '%s=""' % key
else:
if 'isset' in res[key] and res[key]['isset']:
attrstr = '%s="********"' % key
else:
attrstr = '%s=""' % key
if res[key] is not None and 'inheritedfrom' in res[key]:
notes.append(
'Inherited from %s' % res[key]['inheritedfrom'])
if res[key] is not None and 'expression' in res[key]:
notes.append(
('Derived from expression "%s"' %
res[key]['expression']))
if notes:
notestr = '(' + ', '.join(notes) + ')'
output = '{0:<40} {1:>39}'.format(attrstr, notestr)
else:
output = attrstr
print(output)
def do_command(command, server):
global exitcode
global target
@ -247,34 +278,7 @@ def do_command(command, server):
if 'errorcode' in res:
exitcode = res['errorcode']
continue
for key in res.iterkeys():
notes = []
if res[key] is None:
attrstr = '%s=""' % key
elif type(res[key]) == list:
attrstr = '%s=%s' % (key, recurse_format(res[key]))
elif 'value' in res[key] and res[key]['value'] is not None:
attrstr = '%s="%s"' % (key, res[key]['value'])
elif 'value' in res[key] and res[key]['value'] is None:
attrstr = '%s=""' % key
else:
if 'isset' in res[key] and res[key]['isset']:
attrstr = '%s="********"' % key
else:
attrstr = '%s=""' % key
if res[key] is not None and 'inheritedfrom' in res[key]:
notes.append(
'Inherited from %s' % res[key]['inheritedfrom'])
if res[key] is not None and 'expression' in res[key]:
notes.append(
('Derived from expression "%s"' %
res[key]['expression']))
if notes:
notestr = '(' + ', '.join(notes) + ')'
output = '{0:<40} {1:>39}'.format(attrstr, notestr)
else:
output = attrstr
print(output)
print_result(res)
elif argv[0] == 'start':
targpath = fullpath_target(argv[1])
nodename = targpath.split('/')[-3]
@ -360,6 +364,7 @@ def setvalues(attribs):
if 'errorcode' in res:
exitcode = res['errorcode']
sys.stderr.write('Error: ' + res['error'] + '\n')
print_result(res)
def parameterize_attribs(attribs):

View File

@ -365,9 +365,9 @@ def resourcehandler_backend(env, start_response):
except exc.NotFoundException:
start_response('404 Not found', headers)
yield "404 - Request path not recognized"
except exc.InvalidArgumentException:
start_response('400 Bad Request', headers)
yield '400 - Bad Request'
except exc.InvalidArgumentException as e:
start_response('400 Bad Request - ' + str(e), headers)
yield '400 - Bad Request - ' + str(e)
except exc.TargetEndpointUnreachable:
start_response('504 Unreachable Target', headers)
yield '504 - Unreachable Target'

View File

@ -185,9 +185,9 @@ def process_request(connection, request, cfm, authdata, authname, skipauth):
tlvdata.send(connection, {"errorcode": 404,
"error": "Target not found"})
tlvdata.send(connection, {"_requestdone": 1})
except exc.InvalidArgumentException:
except exc.InvalidArgumentException as e:
tlvdata.send(connection, {"errorcode": 400,
"error": "Bad Request"})
"error": "Bad Request - " + str(e)})
tlvdata.send(connection, {"_requestdone": 1})
send_response(hdlr, connection)
return