Use error messages provided by exception class for P_wrapper
This commit is contained in:
		
							parent
							
								
									b9b1879179
								
							
						
					
					
						commit
						901020781c
					
				
					 1 changed files with 19 additions and 24 deletions
				
			
		|  | @ -72,45 +72,40 @@ def delete_synonym(synonym): | ||||||
| 
 | 
 | ||||||
| def P_wrapper(function): | def P_wrapper(function): | ||||||
|     def P_wrapped(thingid, response_type='html'): |     def P_wrapped(thingid, response_type='html'): | ||||||
|         ret = function(thingid) |         try: | ||||||
|         if not isinstance(ret, str): |             return function(thingid) | ||||||
|             return ret |  | ||||||
| 
 | 
 | ||||||
|  |         except exceptions.EtiquetteException as e: | ||||||
|             if response_type == 'html': |             if response_type == 'html': | ||||||
|             flask.abort(404, ret) |                 flask.abort(404, e.error_message) | ||||||
|             else: |             else: | ||||||
|             response = jsonify.make_json_response({'error': ret}) |                 response = {'error_type': e.error_type, 'error_message': e.error_message} | ||||||
|  |                 response = jsonify.make_json_response(response, status=404) | ||||||
|                 flask.abort(response) |                 flask.abort(response) | ||||||
| 
 | 
 | ||||||
|  |         except Exception as e: | ||||||
|  |                 if response_type == 'html': | ||||||
|  |                     flask.abort(500) | ||||||
|  |                 else: | ||||||
|  |                     flask.abort(jsonify.make_response({}, status=500)) | ||||||
|  | 
 | ||||||
|     return P_wrapped |     return P_wrapped | ||||||
| 
 | 
 | ||||||
| @P_wrapper | @P_wrapper | ||||||
| def P_album(albumid): | def P_album(albumid): | ||||||
|     try: |  | ||||||
|     return P.get_album(albumid) |     return P.get_album(albumid) | ||||||
|     except exceptions.NoSuchAlbum: |  | ||||||
|         return 'That album doesnt exist' |  | ||||||
| 
 | 
 | ||||||
| @P_wrapper | @P_wrapper | ||||||
| def P_photo(photoid): | def P_photo(photoid): | ||||||
|     try: |  | ||||||
|     return P.get_photo(photoid) |     return P.get_photo(photoid) | ||||||
|     except exceptions.NoSuchPhoto: |  | ||||||
|         return 'That photo doesnt exist' |  | ||||||
| 
 | 
 | ||||||
| @P_wrapper | @P_wrapper | ||||||
| def P_tag(tagname): | def P_tag(tagname): | ||||||
|     try: |  | ||||||
|     return P.get_tag(tagname) |     return P.get_tag(tagname) | ||||||
|     except exceptions.NoSuchTag as e: |  | ||||||
|         return 'That tag doesnt exist: %s' % tagname |  | ||||||
| 
 | 
 | ||||||
| @P_wrapper | @P_wrapper | ||||||
| def P_user(username): | def P_user(username): | ||||||
|     try: |  | ||||||
|     return P.get_user(username=username) |     return P.get_user(username=username) | ||||||
|     except exceptions.NoSuchUser as e: |  | ||||||
|         return 'That user doesnt exist: %s' % e |  | ||||||
| 
 | 
 | ||||||
| def send_file(filepath, override_mimetype=None): | def send_file(filepath, override_mimetype=None): | ||||||
|     ''' |     ''' | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue