From 542da958db607ee64a531b172110f7ef5190b8e4 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 9 May 2014 16:38:55 -0400 Subject: [PATCH] Have 'bad request' errors be more informative --- TODO | 2 +- confluent_client/bin/confetty | 61 +++++++++++++++------------ confluent_server/confluent/httpapi.py | 6 +-- confluent_server/confluent/sockapi.py | 4 +- 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/TODO b/TODO index 5fd9c0cf..89025569 100644 --- a/TODO +++ b/TODO @@ -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 \ No newline at end of file +-invalid attributes at create time come out as 500 diff --git a/confluent_client/bin/confetty b/confluent_client/bin/confetty index 8d28a405..e733cc08 100755 --- a/confluent_client/bin/confetty +++ b/confluent_client/bin/confetty @@ -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): diff --git a/confluent_server/confluent/httpapi.py b/confluent_server/confluent/httpapi.py index ad243d4b..01217f89 100644 --- a/confluent_server/confluent/httpapi.py +++ b/confluent_server/confluent/httpapi.py @@ -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' diff --git a/confluent_server/confluent/sockapi.py b/confluent_server/confluent/sockapi.py index eac250bf..74e13eee 100644 --- a/confluent_server/confluent/sockapi.py +++ b/confluent_server/confluent/sockapi.py @@ -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