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..9de5c180 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 @@ -163,3 +163,18 @@ 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."