From b6b9b3b225cfce88afd58bdaecab449dd8030c65 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 17 Jan 2017 10:44:00 +0000 Subject: [PATCH] Give a more helpful error when token has expired MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’ve seen quite a few developers encounter the `Invalid token: expired` error message when they’re getting started using the Notify API. When this happens they either raise a support ticket or ask for help on Slack. In every case this has been because the clock on their machine/environment/container isn’t accurate. The error message doesn’t help them figure this out. This commit adds extra detail to the error message so they can fix the problem without having to come to us for help. --- app/authentication/auth.py | 2 +- tests/app/authentication/test_authentication.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/authentication/auth.py b/app/authentication/auth.py index 98212dd94..be89cec2c 100644 --- a/app/authentication/auth.py +++ b/app/authentication/auth.py @@ -94,4 +94,4 @@ def get_decode_errors(auth_token, unsigned_secret): try: decode_jwt_token(auth_token, unsigned_secret) except TokenExpiredError: - raise AuthError("Invalid token: expired", 403) + raise AuthError("Invalid token: expired, check that your system clock is accurate", 403) diff --git a/tests/app/authentication/test_authentication.py b/tests/app/authentication/test_authentication.py index b506c6409..f55cb31a0 100644 --- a/tests/app/authentication/test_authentication.py +++ b/tests/app/authentication/test_authentication.py @@ -320,7 +320,9 @@ def test_should_return_403_when_token_is_expired(notify_api, headers={'Authorization': 'Bearer {}'.format(token)}) assert response.status_code == 403 error_message = json.loads(response.get_data()) - assert error_message['message'] == {'token': ['Invalid token: expired']} + assert error_message['message'] == {'token': [ + 'Invalid token: expired, check that your system clock is accurate' + ]} def __create_get_token(service_id):