diff --git a/lago_python_client/exceptions.py b/lago_python_client/exceptions.py index 605a50c..f04f2a4 100644 --- a/lago_python_client/exceptions.py +++ b/lago_python_client/exceptions.py @@ -24,7 +24,8 @@ def __init__( self.response = response self.detail = detail self.headers = headers + super().__init__(self.response) def __repr__(self) -> str: class_name = self.__class__.__name__ - return f"{class_name}(status_code={self.status_code!r}, detail={self.detail!r})" + return f"{class_name}(response={self.response!r}" diff --git a/tests/fixtures/event_unprocessable_entity.json b/tests/fixtures/event_unprocessable_entity.json new file mode 100644 index 0000000..6cf21af --- /dev/null +++ b/tests/fixtures/event_unprocessable_entity.json @@ -0,0 +1,6 @@ +{ + "status": 422, + "error": "Unprocessable Entity", + "code": "validation_errors", + "error_details": { "transaction_id": ["value_already_exist"] } +} diff --git a/tests/test_event_client.py b/tests/test_event_client.py index 7c8f7f0..7c6046c 100644 --- a/tests/test_event_client.py +++ b/tests/test_event_client.py @@ -45,6 +45,14 @@ def mock_response(): return event_response.read() +def mock_unprocessable_entity_response(): + this_dir = os.path.dirname(os.path.abspath(__file__)) + data_path = os.path.join(this_dir, "fixtures/event_unprocessable_entity.json") + + with open(data_path, "rb") as unprocessable_entity_response: + return unprocessable_entity_response.read() + + def mock_fees_response(): this_dir = os.path.dirname(os.path.abspath(__file__)) data_path = os.path.join(this_dir, "fixtures/fees.json") @@ -68,13 +76,13 @@ def test_valid_create_events_request_with_string_timestamp(httpx_mock: HTTPXMock def test_invalid_create_events_request(httpx_mock: HTTPXMock): - client = Client(api_key="invalid") + client = Client(api_key="886fe239-927d-4072-ab72-6dd345e8dd0d") httpx_mock.add_response( method="POST", url="https://api.getlago.com/api/v1/events", - status_code=401, - content=b"", + status_code=422, + content=mock_unprocessable_entity_response(), ) with pytest.raises(LagoApiError):