Replace some flask.abort with exc.jsonify responses.

This commit is contained in:
voussoir 2021-10-26 12:18:55 -07:00
parent 39f78a7fbe
commit 413f9af568
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
2 changed files with 8 additions and 10 deletions

View file

@ -102,12 +102,10 @@ def get_watch():
videos = [video] videos = [video]
return _render_videos_listing(videos, channel=None, state=None, orderby=None) return _render_videos_listing(videos, channel=None, state=None, orderby=None)
@flasktools.required_fields(['channel_id'], forbid_whitespace=True)
@site.route('/add_channel', methods=['POST']) @site.route('/add_channel', methods=['POST'])
def post_add_channel(): def post_add_channel():
channel_id = request.form.get('channel_id', '') channel_id = request.form.['channel_id']
channel_id = channel_id.strip()
if not channel_id:
flask.abort(400)
if not (len(channel_id) == 24 and channel_id.startswith('UC')): if not (len(channel_id) == 24 and channel_id.startswith('UC')):
# It seems they have given us a username instead. # It seems they have given us a username instead.
try: try:
@ -156,8 +154,8 @@ def post_set_automark(channel_id):
try: try:
channel.set_automark(state, commit=True) channel.set_automark(state, commit=True)
except ycdl.exceptions.InvalidVideoState: except ycdl.exceptions.InvalidVideoState as exc:
flask.abort(400) return flasktools.json_response(exc.jsonify(), status=400)
response = {'id': channel.id, 'automark': channel.automark} response = {'id': channel.id, 'automark': channel.automark}
return flasktools.json_response(response) return flasktools.json_response(response)

View file

@ -20,13 +20,13 @@ def post_mark_video_state():
video.mark_state(state, commit=False) video.mark_state(state, commit=False)
common.ycdldb.commit() common.ycdldb.commit()
except ycdl.exceptions.NoSuchVideo: except ycdl.exceptions.NoSuchVideo as exc:
common.ycdldb.rollback() common.ycdldb.rollback()
flask.abort(404) return flasktools.json_response(exc.jsonify(), status=404)
except ycdl.exceptions.InvalidVideoState: except ycdl.exceptions.InvalidVideoState as exc:
common.ycdldb.rollback() common.ycdldb.rollback()
flask.abort(400) return flasktools.json_response(exc.jsonify(), status=400)
return flasktools.json_response({'video_ids': video_ids, 'state': state}) return flasktools.json_response({'video_ids': video_ids, 'state': state})