diff --git a/src/pylorax/api/errors.py b/src/pylorax/api/errors.py new file mode 100644 index 00000000..77d7f5e2 --- /dev/null +++ b/src/pylorax/api/errors.py @@ -0,0 +1,21 @@ +# +# lorax-composer API server +# +# Copyright (C) 2018 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Returned from the API when ?limit= or ?offset= is given something that does +# not convert into an integer. +BAD_LIMIT_OR_OFFSET = "BadLimitOrOffset" diff --git a/src/pylorax/api/v0.py b/src/pylorax/api/v0.py index 3addb14c..5aecf17a 100644 --- a/src/pylorax/api/v0.py +++ b/src/pylorax/api/v0.py @@ -983,6 +983,7 @@ from pylorax.sysutils import joinpaths from pylorax.api.checkparams import checkparams from pylorax.api.compose import start_build, compose_types from pylorax.api.crossdomain import crossdomain +from pylorax.api.errors import * # pylint: disable=wildcard-import from pylorax.api.projects import projects_list, projects_info, projects_depsolve from pylorax.api.projects import modules_list, modules_info, ProjectsError, repo_to_source from pylorax.api.projects import get_repo_sources, delete_repo_source, source_to_repo, yum_repo_to_file_repo @@ -1025,7 +1026,7 @@ def v0_api(api): limit = int(request.args.get("limit", "20")) offset = int(request.args.get("offset", "0")) except ValueError as e: - return jsonify(status=False, errors=[str(e)]), 400 + return jsonify(status=False, errors=[{"id": BAD_LIMIT_OR_OFFSET, "msg": str(e)}]), 400 with api.config["GITLOCK"].lock: blueprints = take_limits(map(lambda f: f[:-5], list_branch_files(api.config["GITLOCK"].repo, branch)), offset, limit) @@ -1114,7 +1115,7 @@ def v0_api(api): limit = int(request.args.get("limit", "20")) offset = int(request.args.get("offset", "0")) except ValueError as e: - return jsonify(status=False, errors=[str(e)]), 400 + return jsonify(status=False, errors=[{"id": BAD_LIMIT_OR_OFFSET, "msg": str(e)}]), 400 blueprints = [] errors = [] @@ -1465,7 +1466,7 @@ def v0_api(api): limit = int(request.args.get("limit", "20")) offset = int(request.args.get("offset", "0")) except ValueError as e: - return jsonify(status=False, errors=[str(e)]), 400 + return jsonify(status=False, errors=[{"id": BAD_LIMIT_OR_OFFSET, "msg": str(e)}]), 400 try: with api.config["YUMLOCK"].lock: @@ -1670,7 +1671,7 @@ def v0_api(api): limit = int(request.args.get("limit", "20")) offset = int(request.args.get("offset", "0")) except ValueError as e: - return jsonify(status=False, errors=[str(e)]), 400 + return jsonify(status=False, errors=[{"id": BAD_LIMIT_OR_OFFSET, "msg": str(e)}]), 400 if module_names: module_names = module_names.split(",")