Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve LagoApiError details #272

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lago_python_client/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
6 changes: 6 additions & 0 deletions tests/fixtures/event_unprocessable_entity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"status": 422,
"error": "Unprocessable Entity",
"code": "validation_errors",
"error_details": { "transaction_id": ["value_already_exist"] }
}
14 changes: 11 additions & 3 deletions tests/test_event_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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):
Expand Down
Loading