Adding for handling proxy-based errors
This commit is contained in:
parent
7c996e2f48
commit
e2475fb024
|
@ -98,6 +98,10 @@ def login_required(f):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
token = request.headers.get('Authorization').split()[1]
|
token = request.headers.get('Authorization').split()[1]
|
||||||
|
except Exception as e:
|
||||||
|
return dict(message='Token is invalid'), 403
|
||||||
|
|
||||||
|
try:
|
||||||
payload = jwt.decode(token, current_app.config['TOKEN_SECRET'])
|
payload = jwt.decode(token, current_app.config['TOKEN_SECRET'])
|
||||||
except jwt.DecodeError:
|
except jwt.DecodeError:
|
||||||
return dict(message='Token is invalid'), 403
|
return dict(message='Token is invalid'), 403
|
||||||
|
@ -108,7 +112,7 @@ def login_required(f):
|
||||||
|
|
||||||
g.current_user = user_service.get(payload['sub'])
|
g.current_user = user_service.get(payload['sub'])
|
||||||
|
|
||||||
if not g.current_user.id:
|
if not g.current_user:
|
||||||
return dict(message='You are not logged in'), 403
|
return dict(message='You are not logged in'), 403
|
||||||
|
|
||||||
# Tell Flask-Principal the identity changed
|
# Tell Flask-Principal the identity changed
|
||||||
|
|
|
@ -45,11 +45,14 @@ class marshal_items(object):
|
||||||
|
|
||||||
return marshal(resp, self.fields)
|
return marshal(resp, self.fields)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
current_app.logger.exception(e)
|
||||||
# this is a little weird hack to respect flask restful parsing errors on marshaled functions
|
# this is a little weird hack to respect flask restful parsing errors on marshaled functions
|
||||||
if hasattr(e, 'code'):
|
if hasattr(e, 'code'):
|
||||||
return {'message': e.data['message']}, 400
|
if hasattr(e, 'data'):
|
||||||
|
return {'message': e.data['message']}, 400
|
||||||
|
else:
|
||||||
|
return {'message': 'unknown'}, 400
|
||||||
else:
|
else:
|
||||||
current_app.logger.exception(e)
|
|
||||||
return {'message': e.message}, 400
|
return {'message': e.message}, 400
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue