Skip to content

fix: include the HTTP status in BadResponse - #12

Draft
chipkent wants to merge 1 commit into
masterfrom
fix/bad-response-status
Draft

chipkent wants to merge 1 commit into
masterfrom
fix/bad-response-status

Conversation

@chipkent

Copy link
Copy Markdown
Owner

Preview only. This is a draft in the fork showing the exact text of the PR planned for massive-com/client-python. It will be closed, not merged, once the upstream PR is opened.

Fixes #<issue: F5a>

BaseClient._get raises BadResponse(resp.data.decode("utf-8")) for any non-200 response, so the HTTP status is lost. Callers have to parse the body to tell a 403 (not entitled) from a 404.

  • BadResponse takes a keyword-only status and stores it as an attribute; _get passes resp.status.
  • str(exc) and exc.args are still the response body. BadResponse() and BadResponse("msg") still work, with status=None.
  • massive/exceptions.py gets an __all__, so the package's from .exceptions import * does not re-export the new typing.Optional import as massive.Optional.
try:
    client.get_ticker_details("AAPL")
except BadResponse as e:
    if e.status == 403:
        ...  # the key is not entitled to this data

Tests in test_rest/test_bad_response.py drive 403 and 404 through pook and check that construction without a status is unchanged.

BaseClient._get raised BadResponse(resp.data.decode("utf-8")) for any
non-200 response, so the status code was lost. Callers had to guess from
the body whether the key was not entitled (403) or the resource was
missing (404).

BadResponse now takes a keyword-only status argument and stores it as an
attribute, and _get passes resp.status. Positional arguments still go to
Exception unchanged, so str(exc) and exc.args are the same as before, and
BadResponse() still works (status is None).

exceptions.py gets an __all__, so the package's star import does not
re-export typing.Optional as massive.Optional.
@coderabbitai

coderabbitai Bot commented Oct 24, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

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.

1 participant