Update auth module to return consistently formed error messages.

We are trying to get all the error messages to return in the following format:
{result: error,
 message: ['what caused error': 'reason for error']
}
This commit is contained in:
Rebecca Law
2016-06-17 14:22:58 +01:00
parent 5378e6ebc1
commit 40fa394226
2 changed files with 11 additions and 14 deletions

View File

@@ -9,7 +9,7 @@ from functools import wraps
def authentication_response(message, code):
return jsonify(result='error',
message=message
message={"token": [message]}
), code
@@ -28,8 +28,6 @@ def requires_auth():
api_client = fetch_client(get_token_issuer(auth_token))
except TokenDecodeError:
return authentication_response("Invalid token: signature", 403)
if api_client is None:
authentication_response("Invalid credentials", 403)
for secret in api_client['secret']:
try:
@@ -45,7 +43,7 @@ def requires_auth():
errors_resp = authentication_response("Invalid token: signature", 403)
if not api_client['secret']:
errors_resp = authentication_response("Invalid token: signature", 403)
errors_resp = authentication_response("Invalid token: no api keys for service", 403)
current_app.logger.info(errors_resp)
return errors_resp