From 2c0eff7d9bee12c256130738d47dfb74315699d6 Mon Sep 17 00:00:00 2001 From: gnaponie Date: Nov 27 2017 13:12:34 +0000 Subject: Correct an error handling The 'error' object in the handling of the JSONBadRequest error doesn't have any attribute 'data'. Trying to access to that attribute was raising another exception, so it was not possible to understand the real error. --- diff --git a/resultsdb/controllers/api_v2.py b/resultsdb/controllers/api_v2.py index 0bcde79..9eab886 100644 --- a/resultsdb/controllers/api_v2.py +++ b/resultsdb/controllers/api_v2.py @@ -229,7 +229,7 @@ def get_groups(): try: args = RP['get_groups'].parse_args() except JSONBadRequest as error: - return jsonify({"message": "Malformed Request: %s" % error.data['message']}), error.code + return jsonify({"message": "Malformed Request: %s" % error}), error.code except HTTPException as error: return jsonify(error.data), error.code @@ -285,7 +285,7 @@ def create_group(): try: args = RP['create_group'].parse_args() except JSONBadRequest as error: - return jsonify({"message": "Malformed Request: %s" % error.data['message']}), error.code + return jsonify({"message": "Malformed Request: %s" % error}), error.code except HTTPException as error: return jsonify(error.data), error.code @@ -385,7 +385,7 @@ def __get_results_parse_args(): try: args = RP['get_results'].parse_args() except JSONBadRequest as error: - retval["error"] = (jsonify({"message": "Malformed Request: %s" % error.data['message']}), error.code) + retval["error"] = (jsonify({"message": "Malformed Request: %s" % error}), error.code) return retval except HTTPException as error: retval["error"] = (jsonify(error.data), error.code) @@ -574,7 +574,7 @@ def create_result(): try: args = RP['create_result'].parse_args() except JSONBadRequest as error: - return jsonify({"message": "Malformed Request: %s" % error.data['message']}), error.code + return jsonify({"message": "Malformed Request: %s" % error}), error.code except HTTPException as error: return jsonify(error.data), error.code @@ -730,7 +730,7 @@ def get_testcases(): # page = None, limit = QUERY_LIMIT): try: args = RP['get_testcases'].parse_args() except JSONBadRequest as error: - return jsonify({"message": "Malformed Request: %s" % error.data['message']}), error.code + return jsonify({"message": "Malformed Request: %s" % error}), error.code except HTTPException as error: return jsonify(error.data), error.code @@ -765,7 +765,7 @@ def create_testcase(): try: args = RP['create_testcase'].parse_args() except JSONBadRequest as error: - return jsonify({"message": "Malformed Request: %s" % error.data['message']}), error.code + return jsonify({"message": "Malformed Request: %s" % error}), error.code except HTTPException as error: return jsonify(error.data), error.code