From e58c50c94fae94aa3933bf363aa6c47faf0a0933 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 16 Jun 2017 02:24:57 -0700 Subject: [PATCH] Return 400 instead of 500 for /albums/create_album errors. --- .../etiquette_flask/etiquette_flask/etiquette_flask.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py b/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py index 149fd5b..a36552d 100644 --- a/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py +++ b/frontends/etiquette_flask/etiquette_flask/etiquette_flask.py @@ -517,14 +517,18 @@ def get_albums_json(): @site.route('/albums/create_album', methods=['POST']) def post_albums_create(): - print(dict(request.form)) title = request.form.get('title', None) description = request.form.get('description', None) parent = request.form.get('parent', None) if parent is not None: parent = P_album(parent) - album = P.new_album(title=title, description=description) + try: + album = P.new_album(title=title, description=description) + except etiquette.exceptions.EtiquetteException as e: + response = etiquette.jsonify.exception(e) + response = jsonify.make_json_response(response, status=400) + flask.abort(response) if parent is not None: parent.add(album) response = etiquette.jsonify.album(album, minimal=False)