Add error IDs for common source-related errors.

(cherry picked from commit e43adfc7af)
This commit is contained in:
Chris Lumens 2018-08-08 17:52:21 -04:00
parent f67e2c5d52
commit c1af7dd69d
2 changed files with 10 additions and 4 deletions

View File

@ -29,6 +29,9 @@ BUILD_IN_WRONG_STATE = "BuildInWrongState"
# given that contains invalid characters.
INVALID_NAME = "InvalidName"
# Returned from the API when someone tries to modify an immutable system source.
SYSTEM_SOURCE = "SystemSource"
# Returned from the API when a blueprint that was requested does not exist.
UNKNOWN_BLUEPRINT = "UnknownBlueprint"
@ -41,5 +44,8 @@ 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 source that was requested does not exist.
UNKNOWN_SOURCE = "UnknownSource"
# Returned from the API when a UUID that was requested does not exist.
UNKNOWN_UUID = "UnknownUUID"

View File

@ -1572,7 +1572,7 @@ def v0_api(api):
with api.config["DNFLOCK"].lock:
repo = api.config["DNFLOCK"].dbo.repos.get(source, None)
if not repo:
errors.append("%s is not a valid source" % source)
errors.append({"id": UNKNOWN_SOURCE, "msg": "%s is not a valid source" % source})
continue
sources[repo.id] = repo_to_source(repo, repo.id in system_sources)
@ -1596,7 +1596,7 @@ def v0_api(api):
system_sources = get_repo_sources("/etc/yum.repos.d/*.repo")
if source["name"] in system_sources:
return jsonify(status=False, errors=["%s is a system source, it cannot be changed." % source["name"]]), 400
return jsonify(status=False, errors=[{"id": SYSTEM_SOURCE, "msg": "%s is a system source, it cannot be changed." % source["name"]}]), 400
try:
# Remove it from the RepoDict (NOTE that this isn't explicitly supported by the DNF API)
@ -1656,7 +1656,7 @@ def v0_api(api):
system_sources = get_repo_sources("/etc/yum.repos.d/*.repo")
if source_name in system_sources:
return jsonify(status=False, errors=["%s is a system source, it cannot be deleted." % source_name]), 400
return jsonify(status=False, errors=[{"id": SYSTEM_SOURCE, "msg": "%s is a system source, it cannot be deleted." % source_name}]), 400
share_dir = api.config["COMPOSER_CFG"].get("composer", "repo_dir")
try:
# Remove the file entry for the source
@ -1672,7 +1672,7 @@ def v0_api(api):
except ProjectsError as e:
log.error("(v0_projects_source_delete) %s", str(e))
return jsonify(status=False, errors=[str(e)]), 400
return jsonify(status=False, errors=[{"id": UNKNOWN_SOURCE, "msg": str(e)}]), 400
return jsonify(status=True)