fix(api): check HTTP status before decoding POST responses - #157
Open
JianYan11 wants to merge 1 commit into
Open
fix(api): check HTTP status before decoding POST responses#157JianYan11 wants to merge 1 commit into
JianYan11 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #95.
Move
response.raise_for_status()immediately after the Table API request, before the POST branch readsresponse.json()["result"]["sys_id"].Previously, a failed POST with a JSON error body raised
KeyError: 'result', and a failed POST with an HTML error page raisedJSONDecodeError. Both masked the actual HTTP error. Successful POST polling and other method behavior are unchanged.Tests
Added offline tests using real
requests.Responseobjects, a lightweight instance stand-in, and mocked HTTP calls/sleep:HTTPErrorresponse, without decoding or polling.sys_idand returns the original creation response.Before the fix: 2 failed, 7 passed (the two POST error cases).
After the fix: 9 passed.
PYTHONPATH=src uv run --no-project --python 3.12 \ --with-requirements requirements.txt --with 'playwright==1.44.0' --with pytest -- \ python -m pytest tests/test_api_utils.py -qBlack 24.10.0 and
git diff --checkpass. No browser was launched, no ServiceNow instance was contacted, and the live-instance integration suite was not run.AI assistance: implemented and tested with OpenAI Codex.