From a1803c218f8f17425fc77c8633d2d8d3c6ed63fa Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Wed, 8 Aug 2018 17:16:00 -0400 Subject: [PATCH] Add error IDs for unknown modules and unknown projects. (cherry picked from commit 2adcfc9563a2fb2f1d9fd65f3819768dc327b145) --- src/pylorax/api/errors.py | 6 ++++++ src/pylorax/api/v0.py | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/pylorax/api/errors.py b/src/pylorax/api/errors.py index c4edfe7b..d1296240 100644 --- a/src/pylorax/api/errors.py +++ b/src/pylorax/api/errors.py @@ -35,5 +35,11 @@ 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 module that was requested does not exist. +UNKNOWN_MODULE = "UnknownModule" + +# Returned from the API when a project that was requested does not exist. +UNKNOWN_PROJECT = "UnknownProject" + # 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 b0d43b2f..d07ed716 100644 --- a/src/pylorax/api/v0.py +++ b/src/pylorax/api/v0.py @@ -1508,6 +1508,11 @@ def v0_api(api): log.error("(v0_projects_info) %s", str(e)) return jsonify(status=False, errors=[str(e)]), 400 + if not projects: + msg = "one of the requested projects does not exist: %s" % project_names + log.error("(v0_projects_info) %s", msg) + return jsonify(status=False, errors=[{"id": UNKNOWN_PROJECT, "msg": msg}]), 400 + return jsonify(projects=projects) @api.route("/api/v0/projects/depsolve", defaults={'project_names': ""}) @@ -1526,6 +1531,11 @@ def v0_api(api): log.error("(v0_projects_depsolve) %s", str(e)) return jsonify(status=False, errors=[str(e)]), 400 + if not deps: + msg = "one of the requested projects does not exist: %s" % project_names + log.error("(v0_projects_depsolve) %s", msg) + return jsonify(status=False, errors=[{"id": UNKNOWN_PROJECT, "msg": msg}]), 400 + return jsonify(projects=deps) @api.route("/api/v0/projects/source/list") @@ -1690,6 +1700,11 @@ def v0_api(api): log.error("(v0_modules_list) %s", str(e)) return jsonify(status=False, errors=[str(e)]), 400 + if module_names and not available: + msg = "one of the requested modules does not exist: %s" % module_names + log.error("(v0_modules_list) %s", msg) + return jsonify(status=False, errors=[{"id": UNKNOWN_MODULE, "msg": msg}]), 400 + modules = take_limits(available, offset, limit) return jsonify(modules=modules, offset=offset, limit=limit, total=len(available)) @@ -1711,7 +1726,7 @@ def v0_api(api): if not modules: msg = "one of the requested modules does not exist: %s" % module_names log.error("(v0_modules_info) %s", msg) - return jsonify(status=False, errors=[msg]), 400 + return jsonify(status=False, errors=[{"id": UNKNOWN_MODULE, "msg": msg}]), 400 return jsonify(modules=modules)