Skip to content

fix(api): check HTTP status before decoding POST responses - #157

Open
JianYan11 wants to merge 1 commit into
ServiceNow:mainfrom
JianYan11:fix/table-api-http-error-order
Open

fix(api): check HTTP status before decoding POST responses#157
JianYan11 wants to merge 1 commit into
ServiceNow:mainfrom
JianYan11:fix/table-api-http-error-order

Conversation

@JianYan11

Copy link
Copy Markdown

Summary

Fixes #95.

Move response.raise_for_status() immediately after the Table API request, before the POST branch reads response.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 raised JSONDecodeError. Both masked the actual HTTP error. Successful POST polling and other method behavior are unchanged.

Tests

Added offline tests using real requests.Response objects, a lightweight instance stand-in, and mocked HTTP calls/sleep:

  • JSON 401 and HTML 503 responses for GET, POST, PUT, and DELETE preserve the original HTTPError response, without decoding or polling.
  • A successful POST still polls for its created sys_id and 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 -q

Black 24.10.0 and git diff --check pass. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Table API utility function misplaced raise

1 participant