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] |     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) | ||||||
|  |  | ||||||
|  | @ -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}) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue