From 56561af158e40a19963230a2edea3e74cbc2ec91 Mon Sep 17 00:00:00 2001 From: "Haig (Hike) Hovsepian" Date: Tue, 23 Apr 2024 10:05:05 -0500 Subject: [PATCH 1/3] add suggested_user_message to SDK v2 err response --- smartcar/exception.py | 2 ++ tests/e2e/test_exception.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/smartcar/exception.py b/smartcar/exception.py index 825df577..6afad842 100644 --- a/smartcar/exception.py +++ b/smartcar/exception.py @@ -88,6 +88,7 @@ def exception_factory(status_code: int, headers: dict, body: str): resolution=response.get("resolution"), detail=response.get("detail"), retry_after=headers.get("Retry-After"), + suggested_user_message=response.get("suggestedUserMessage"), ) else: return SmartcarException( @@ -99,6 +100,7 @@ def exception_factory(status_code: int, headers: dict, body: str): doc_url=response.get("docURL"), resolution=response.get("resolution"), detail=response.get("detail"), + suggested_user_message=response.get("suggestedUserMessage"), ) # Weird... diff --git a/tests/e2e/test_exception.py b/tests/e2e/test_exception.py index 8f63cdbf..a114ea88 100644 --- a/tests/e2e/test_exception.py +++ b/tests/e2e/test_exception.py @@ -163,3 +163,17 @@ def test_retry_after_found(): except Exception as e: assert isinstance(e, SmartcarException) assert e.retry_after == 5000 + +def test_suggested_user_message(): + """ + test that we can get the retry_after amount + """ + try: + raise exception_factory( + 429, + {"Retry-After": 5000, "Content-Type": "application/json"}, + '{"statusCode":429,"type":"RATE_LIMIT","code":"Vehicle","resolution":{"type":"RETRY_LATER"},"requestId":"e0027f5f-4411-4247-a54d-e34c157d84c1", "suggestedUserMessage": "Please try again later."}', + ) + except Exception as e: + assert isinstance(e, SmartcarException) + assert e.suggested_user_message == "Please try again later." From f734227821bff73f384ff352e63ddcfb362ca06d Mon Sep 17 00:00:00 2001 From: "Haig (Hike) Hovsepian" Date: Tue, 23 Apr 2024 10:20:49 -0500 Subject: [PATCH 2/3] change err field count value in pre-existing test --- tests/e2e/test_exception.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/test_exception.py b/tests/e2e/test_exception.py index a114ea88..29e60cca 100644 --- a/tests/e2e/test_exception.py +++ b/tests/e2e/test_exception.py @@ -71,8 +71,8 @@ def test_out_of_permission_scope(ford_car): except Exception as e: assert isinstance(e, SmartcarException) - # 8 fields stated in exception.py + 'message' - assert len(e.__dict__.keys()) == 9 + # 9 fields stated in exception.py + 'message' + assert len(e.__dict__.keys()) == 10 assert e.status_code == 403 assert e.code is None From 52b6b01682210234ec523ac19f120e21b8780f2a Mon Sep 17 00:00:00 2001 From: "Haig (Hike) Hovsepian" Date: Wed, 24 Apr 2024 10:32:33 -0500 Subject: [PATCH 3/3] use black lib to fix formatting so build passes --- tests/e2e/test_exception.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/e2e/test_exception.py b/tests/e2e/test_exception.py index 29e60cca..9de5c180 100644 --- a/tests/e2e/test_exception.py +++ b/tests/e2e/test_exception.py @@ -164,6 +164,7 @@ def test_retry_after_found(): assert isinstance(e, SmartcarException) assert e.retry_after == 5000 + def test_suggested_user_message(): """ test that we can get the retry_after amount