Add jsonify.exception
This commit is contained in:
parent
6912a1a56e
commit
0bac643f2d
2 changed files with 15 additions and 17 deletions
|
@ -22,6 +22,13 @@ def album(a, minimal=False):
|
||||||
|
|
||||||
return j
|
return j
|
||||||
|
|
||||||
|
def exception(e):
|
||||||
|
j = {
|
||||||
|
'error_type': e.error_type,
|
||||||
|
'error_message': e.error_message,
|
||||||
|
}
|
||||||
|
return j
|
||||||
|
|
||||||
def photo(p, include_albums=True, include_tags=True):
|
def photo(p, include_albums=True, include_tags=True):
|
||||||
tags = p.tags()
|
tags = p.tags()
|
||||||
tags.sort(key=lambda x: x.name)
|
tags.sort(key=lambda x: x.name)
|
||||||
|
|
|
@ -86,7 +86,7 @@ def P_wrapper(function):
|
||||||
if response_type == 'html':
|
if response_type == 'html':
|
||||||
flask.abort(status, e.error_message)
|
flask.abort(status, e.error_message)
|
||||||
else:
|
else:
|
||||||
response = {'error_type': e.error_type, 'error_message': e.error_message}
|
response = jsonify.exception(e)
|
||||||
response = jsonify.make_json_response(response, status=status)
|
response = jsonify.make_json_response(response, status=status)
|
||||||
flask.abort(response)
|
flask.abort(response)
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ def get_register():
|
||||||
def post_login():
|
def post_login():
|
||||||
if session_manager.get(request):
|
if session_manager.get(request):
|
||||||
e = exceptions.AlreadySignedIn()
|
e = exceptions.AlreadySignedIn()
|
||||||
response = {'error_type': e.error_type, 'error_message': e.error_message}
|
response = jsonify.exception(e)
|
||||||
return jsonify.make_json_response(response, status=403)
|
return jsonify.make_json_response(response, status=403)
|
||||||
|
|
||||||
username = request.form['username']
|
username = request.form['username']
|
||||||
|
@ -227,7 +227,7 @@ def post_login():
|
||||||
user = P.login(user.id, password)
|
user = P.login(user.id, password)
|
||||||
except (exceptions.NoSuchUser, exceptions.WrongLogin):
|
except (exceptions.NoSuchUser, exceptions.WrongLogin):
|
||||||
e = exceptions.WrongLogin()
|
e = exceptions.WrongLogin()
|
||||||
response = {'error_type': e.error_type, 'error_message': e.error_message}
|
response = jsonify.exception(e)
|
||||||
return jsonify.make_json_response(response, status=422)
|
return jsonify.make_json_response(response, status=422)
|
||||||
session = sessions.Session(request, user)
|
session = sessions.Session(request, user)
|
||||||
session_manager.add(session)
|
session_manager.add(session)
|
||||||
|
@ -239,7 +239,7 @@ def post_login():
|
||||||
def post_register():
|
def post_register():
|
||||||
if session_manager.get(request):
|
if session_manager.get(request):
|
||||||
e = exceptions.AlreadySignedIn()
|
e = exceptions.AlreadySignedIn()
|
||||||
response = {'error_type': e.error_type, 'error_message': e.error_message}
|
response = jsonify.exception(e)
|
||||||
return jsonify.make_json_response(response, status=403)
|
return jsonify.make_json_response(response, status=403)
|
||||||
|
|
||||||
username = request.form['username']
|
username = request.form['username']
|
||||||
|
@ -256,10 +256,7 @@ def post_register():
|
||||||
try:
|
try:
|
||||||
user = P.register_user(username, password_1)
|
user = P.register_user(username, password_1)
|
||||||
except exceptions.EtiquetteException as e:
|
except exceptions.EtiquetteException as e:
|
||||||
response = {
|
response = jsonify.exception(e)
|
||||||
'error_type': e.error_type,
|
|
||||||
'error_message': e.error_message,
|
|
||||||
}
|
|
||||||
return jsonify.make_json_response(response, status=400)
|
return jsonify.make_json_response(response, status=400)
|
||||||
|
|
||||||
session = sessions.Session(request, user)
|
session = sessions.Session(request, user)
|
||||||
|
@ -663,7 +660,7 @@ def post_album_add_tag(albumid):
|
||||||
try:
|
try:
|
||||||
tag = P_tag(tag)
|
tag = P_tag(tag)
|
||||||
except exceptions.NoSuchTag as e:
|
except exceptions.NoSuchTag as e:
|
||||||
response = {'error_type': e.error_type, 'error_message': e.error_message}
|
response = jsonify.exception(e)
|
||||||
return jsonify.make_json_response(response, status=404)
|
return jsonify.make_json_response(response, status=404)
|
||||||
recursive = request.form.get('recursive', False)
|
recursive = request.form.get('recursive', False)
|
||||||
recursive = helpers.truthystring(recursive)
|
recursive = helpers.truthystring(recursive)
|
||||||
|
@ -683,10 +680,7 @@ def post_photo_add_remove_tag_core(photoid, tagname, add_or_remove):
|
||||||
elif add_or_remove == 'remove':
|
elif add_or_remove == 'remove':
|
||||||
photo.remove_tag(tag)
|
photo.remove_tag(tag)
|
||||||
except exceptions.EtiquetteException as e:
|
except exceptions.EtiquetteException as e:
|
||||||
response = {
|
response = jsonify.exception(e)
|
||||||
'error_type': e.error_type,
|
|
||||||
'error_message': e.error_message,
|
|
||||||
}
|
|
||||||
response = jsonify.make_json_response(response, status=400)
|
response = jsonify.make_json_response(response, status=400)
|
||||||
flask.abort(response)
|
flask.abort(response)
|
||||||
|
|
||||||
|
@ -724,10 +718,7 @@ def post_tag_create_delete_core(tagname, function):
|
||||||
response = function(tagname)
|
response = function(tagname)
|
||||||
status = 200
|
status = 200
|
||||||
except exceptions.EtiquetteException as e:
|
except exceptions.EtiquetteException as e:
|
||||||
response = {
|
response = jsonify.exception(e)
|
||||||
'error_type': e.error_type,
|
|
||||||
'error_message': e.error_message,
|
|
||||||
}
|
|
||||||
status = 400
|
status = 400
|
||||||
#print(response)
|
#print(response)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue