Skip to content

fix: surface nba api http response errors#679

Open
vikramdurai wants to merge 1 commit into
swar:masterfrom
vikramdurai:issue-678-live-http-error-handling
Open

fix: surface nba api http response errors#679
vikramdurai wants to merge 1 commit into
swar:masterfrom
vikramdurai:issue-678-live-http-error-handling

Conversation

@vikramdurai

Copy link
Copy Markdown

Summary

Fixes #678.

This updates the shared HTTP layer so NBA API response failures are surfaced before JSON parsing turns them into misleading JSONDecodeErrors. It also adds the live CDN Referer header needed for current nba_api.live requests.

This includes the live header fix from #671, then extends the error handling beyond the narrower approaches in #659 and #657: HTTP status is checked before parsing, structured response context is preserved, partial-content responses are rejected, and JSON decode failures include useful response metadata. #675 touches session/test isolation but does not address the HTTP status / non-JSON response handling in #678.

Changes

  • Add NBAError, NBAHTTPError, NBARequestError, and NBAJSONDecodeError
  • Raise NBAHTTPError for non-2xx responses before parsing response bodies
  • Raise NBAHTTPError for 206 Partial Content
  • Wrap JSON parse failures in NBAJSONDecodeError with status, URL, content type, body preview, and reason hint
  • Wrap request/transport failures in NBARequestError
  • Add Referer: https://www.nba.com/ to live endpoint default headers
  • Add unit coverage for observed NBA/CDN response shapes

Verification

PYTHONPATH=src /private/tmp/nba_api_contrib_venv/bin/python -m pytest tests/unit
PYTHONPATH=src /private/tmp/nba_api_contrib_venv/bin/python -m ruff check src tests/unit/http/test_legacy_debug_usage.py

Result:

  • 528 passed, 1 warning
  • Ruff passed

Also manually verified live behavior:

  • ScoreBoard() succeeds with default headers
  • Removing the live Referer raises NBAHTTPError with 403 text/html access_denied instead of surfacing as a JSON parse failure

@vikramdurai vikramdurai requested a review from swar as a code owner June 16, 2026 14:09
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.

[Bug]: nba_api.live silently swallows 403s and raises a misleading JSONDecodeError

1 participant