From 07528a431e3fa9c40e0bb293eaa37e9776dd1ba9 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Wed, 8 Aug 2018 16:27:30 -0400 Subject: [PATCH] Add error IDs for when an unknown commit is requested. --- src/pylorax/api/errors.py | 3 +++ src/pylorax/api/v0.py | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pylorax/api/errors.py b/src/pylorax/api/errors.py index e2be52c6..c4edfe7b 100644 --- a/src/pylorax/api/errors.py +++ b/src/pylorax/api/errors.py @@ -32,5 +32,8 @@ INVALID_NAME = "InvalidName" # Returned from the API when a blueprint that was requested does not exist. UNKNOWN_BLUEPRINT = "UnknownBlueprint" +# Returned from the API when a commit that was requested does not exist. +UNKNOWN_COMMIT = "UnknownCommit" + # Returned from the API when a UUID that was requested does not exist. UNKNOWN_UUID = "UnknownUUID" diff --git a/src/pylorax/api/v0.py b/src/pylorax/api/v0.py index 6ac0e0e8..c3cb7eca 100644 --- a/src/pylorax/api/v0.py +++ b/src/pylorax/api/v0.py @@ -1270,7 +1270,7 @@ def v0_api(api): workspace_write(api.config["GITLOCK"].repo, branch, blueprint) except Exception as e: log.error("(v0_blueprints_undo) %s", str(e)) - return jsonify(status=False, errors=[str(e)]), 400 + return jsonify(status=False, errors=[{"id": UNKNOWN_COMMIT, "msg": str(e)}]), 400 else: return jsonify(status=True) @@ -1323,7 +1323,7 @@ def v0_api(api): old_blueprint = read_recipe_commit(api.config["GITLOCK"].repo, branch, blueprint_name, from_commit) except Exception as e: log.error("(v0_blueprints_diff) %s", str(e)) - return jsonify(status=False, errors=[str(e)]), 400 + return jsonify(status=False, errors=[{"id": UNKNOWN_COMMIT, "msg": str(e)}]), 400 try: if to_commit == "WORKSPACE": @@ -1341,7 +1341,7 @@ def v0_api(api): new_blueprint = read_recipe_commit(api.config["GITLOCK"].repo, branch, blueprint_name, to_commit) except Exception as e: log.error("(v0_blueprints_diff) %s", str(e)) - return jsonify(status=False, errors=[str(e)]), 400 + return jsonify(status=False, errors=[{"id": UNKNOWN_COMMIT, "msg": str(e)}]), 400 diff = recipe_diff(old_blueprint, new_blueprint) return jsonify(diff=diff)