Skip to content
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
4 changes: 3 additions & 1 deletion aiogithubapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ async def async_call_api(
if message is not None:
if exception := MESSAGE_EXCEPTIONS.get(message):
raise exception(message)
raise GitHubException(message)
# For a 201 Created response, we assume the operation was successful and ignore any "message" field.
if response.status != HttpStatusCode.CREATED:
raise GitHubException(message)

if endpoint == "/graphql" and response.data.get("errors", []):
raise GitHubGraphQLException(
Expand Down
16 changes: 16 additions & 0 deletions tests/client/test_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,19 @@ async def test_response_object(github_api: GitHubAPI, mock_response: MockRespons
mock_response.mock_headers = {"Link": ""}
response = await github_api.generic("/generic")
assert response.page_number == 1


@pytest.mark.asyncio
async def test_created_with_message_handling(github_api: GitHubAPI, mock_response: MockResponse):
"""Ensure 201 Created with a message does not raise an exception."""
mock_response.mock_status = 201
mock_response.mock_data = {
"message": "Some info message",
"id": 123,
"name": "created-object"
}
response = await github_api.generic("/generic")
assert response.status == HttpStatusCode.CREATED
assert response.data["message"] == "Some info message"
assert response.data["id"] == 123
assert response.data["name"] == "created-object"