Replace some flask.abort with exc.jsonify responses.
This commit is contained in:
parent
39f78a7fbe
commit
413f9af568
2 changed files with 8 additions and 10 deletions
|
@ -102,12 +102,10 @@ def get_watch():
|
|||
videos = [video]
|
||||
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'])
|
||||
def post_add_channel():
|
||||
channel_id = request.form.get('channel_id', '')
|
||||
channel_id = channel_id.strip()
|
||||
if not channel_id:
|
||||
flask.abort(400)
|
||||
channel_id = request.form.['channel_id']
|
||||
if not (len(channel_id) == 24 and channel_id.startswith('UC')):
|
||||
# It seems they have given us a username instead.
|
||||
try:
|
||||
|
@ -156,8 +154,8 @@ def post_set_automark(channel_id):
|
|||
|
||||
try:
|
||||
channel.set_automark(state, commit=True)
|
||||
except ycdl.exceptions.InvalidVideoState:
|
||||
flask.abort(400)
|
||||
except ycdl.exceptions.InvalidVideoState as exc:
|
||||
return flasktools.json_response(exc.jsonify(), status=400)
|
||||
|
||||
response = {'id': channel.id, 'automark': channel.automark}
|
||||
return flasktools.json_response(response)
|
||||
|
|
|
@ -20,13 +20,13 @@ def post_mark_video_state():
|
|||
video.mark_state(state, commit=False)
|
||||
common.ycdldb.commit()
|
||||
|
||||
except ycdl.exceptions.NoSuchVideo:
|
||||
except ycdl.exceptions.NoSuchVideo as exc:
|
||||
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()
|
||||
flask.abort(400)
|
||||
return flasktools.json_response(exc.jsonify(), status=400)
|
||||
|
||||
return flasktools.json_response({'video_ids': video_ids, 'state': state})
|
||||
|
||||
|
|
Loading…
Reference in a new issue