[copr] master: Make the api return 500 status code when something goes wrong. (802c4e8)
bkabrda at fedoraproject.org
bkabrda at fedoraproject.org
Mon Feb 4 11:02:42 UTC 2013
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
>---------------------------------------------------------------
commit 802c4e8b299faa1768bba8a83d20a8e13fc69752
Author: Pierre-Yves Chibon <pingou at pingoured.fr>
Date: Mon Feb 4 11:43:02 2013 +0100
Make the api return 500 status code when something goes wrong.
>---------------------------------------------------------------
coprs_frontend/coprs/views/api_ns/api_general.py | 17 ++++++++++++++---
1 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/coprs_frontend/coprs/views/api_ns/api_general.py b/coprs_frontend/coprs/views/api_ns/api_general.py
index 735da98..7c87388 100644
--- a/coprs_frontend/coprs/views/api_ns/api_general.py
+++ b/coprs_frontend/coprs/views/api_ns/api_general.py
@@ -53,6 +53,7 @@ def api_new_copr():
"""
form = forms.CoprFormFactory.create_form_cls()(csrf_enabled=False)
+ httpcode = 200
if form.validate_on_submit():
infos = []
try:
@@ -79,14 +80,20 @@ def api_new_copr():
db.session.commit()
except exceptions.DuplicateException, err:
output = {'output': 'notok', 'error': err}
+ httpcode = 500
db.session.rollback()
else:
- errormsg = "\n".join(form.errors['name'])
+ errormsg = ''
+ if form.errors:
+ errormsg = "\n".join(form.errors['name'])
errormsg = errormsg.replace('"', "'")
output = {'output': 'notok', 'error': errormsg}
+ httpcode = 500
- return flask.jsonify(output)
+ jsonout = flask.jsonify(output)
+ jsonout.status_code = httpcode
+ return jsonout
@api_ns.route('/owned/')
@@ -101,6 +108,7 @@ def api_coprs_by_owner(username=None):
"""
username = flask.request.args.get('username', None) or username
+ httpcode = 200
if 'username':
query = coprs_logic.CoprsLogic.get_multiple(flask.g.user,
user_relation='owned', username=username)
@@ -113,5 +121,8 @@ def api_coprs_by_owner(username=None):
'instructions': repo.instructions})
else:
output = {'output': 'notok', 'error': 'Invalid request'}
+ httpcode = 500
- return flask.jsonify(output)
+ jsonout = flask.jsonify(output)
+ jsonout.status_code = httpcode
+ return jsonout
More information about the copr-devel
mailing list