Skip to content

feat: add raise_on_status to RESTClient - #13

Draft
chipkent wants to merge 1 commit into
fix/bad-response-statusfrom
feat/rest-raise-on-status
Draft

chipkent wants to merge 1 commit into
fix/bad-response-statusfrom
feat/rest-raise-on-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: F5b>

Builds on #12 (BadResponse.status).

The client retries 413, 429, 499, 500, 502, 503 and 504. If the last retry still gets one of them, urllib3 raises MaxRetryError, so code that catches BadResponse misses rate limits and server errors.

  • New RESTClient(raise_on_status=...), passed to the client's urllib3 Retry, for both the main client and client.vx.
  • True (the default) keeps today's MaxRetryError. With False, the client raises BadResponse with the status and body. Attempts and backoff are unchanged.
client = RESTClient(raise_on_status=False)
try:
    client.get_market_status()
except BadResponse as e:
    if e.status == 429:
        ...  # still rate limited after the retries

Why not a custom Retry through connection_pool_kw (massive-com#1040)? That already works, and this PR adds no new capability. But it replaces the whole Retry: the caller must copy the client's status list and backoff, which are not public and can drift, and the retries argument silently stops applying. A plain keyword argument changes one setting and keeps the rest.

Tests use a local HTTP server, because pook replaces urllib3's urlopen, where retries happen. The backoff sleep is patched out.

@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.

The client retries 413, 429, 499, 500, 502, 503 and 504. When the last
retry still gets one of those statuses, urllib3 raises MaxRetryError, so
code that catches BadResponse misses rate limits and server errors.

Add a raise_on_status argument, passed to the client's Retry. It defaults
to True, which keeps today's MaxRetryError. With raise_on_status=False,
urllib3 returns the last response and _get raises BadResponse with its
status and body. The number of attempts and the backoff do not change.

A custom Retry can already be passed through connection_pool_kw, but it
replaces the client's status list and backoff, and makes the retries
argument a no-op.
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