Skip to content

Commit 66174b8

Browse files
mbrisxludeeus
andauthored
fix: omit error-check for 201 responses in async_call_api (#391)
* fix: omit error-check for 201 responses in async_call_api Skip error-checking for responses with a 201 status code in async_call_api, preventing false error raises for successful REST operations. * Extend test * Update aiogithubapi/client.py --------- Co-authored-by: Joakim Sørensen <joasoe@proton.me>
1 parent d9716de commit 66174b8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

aiogithubapi/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ async def async_call_api(
185185
if message is not None:
186186
if exception := MESSAGE_EXCEPTIONS.get(message):
187187
raise exception(message)
188-
raise GitHubException(message)
188+
# For a 201 Created response, we assume the operation was successful and ignore any "message" field.
189+
if response.status != HttpStatusCode.CREATED:
190+
raise GitHubException(message)
189191

190192
if endpoint == "/graphql" and response.data.get("errors", []):
191193
raise GitHubGraphQLException(

tests/client/test_operation.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,19 @@ async def test_response_object(github_api: GitHubAPI, mock_response: MockRespons
211211
mock_response.mock_headers = {"Link": ""}
212212
response = await github_api.generic("/generic")
213213
assert response.page_number == 1
214+
215+
216+
@pytest.mark.asyncio
217+
async def test_created_with_message_handling(github_api: GitHubAPI, mock_response: MockResponse):
218+
"""Ensure 201 Created with a message does not raise an exception."""
219+
mock_response.mock_status = 201
220+
mock_response.mock_data = {
221+
"message": "Some info message",
222+
"id": 123,
223+
"name": "created-object"
224+
}
225+
response = await github_api.generic("/generic")
226+
assert response.status == HttpStatusCode.CREATED
227+
assert response.data["message"] == "Some info message"
228+
assert response.data["id"] == 123
229+
assert response.data["name"] == "created-object"

0 commit comments

Comments
 (0)