Repository navigation
fix(no-ticket): show an error when the API host returns an HTML page - #560
Open
cloudsmith-iduffy wants to merge 1 commit into
Open
cloudsmith-iduffy wants to merge 1 commit into
cloudsmith-iduffy wants to merge 1 commit into
Conversation
A TLS-intercepting proxy, a captive portal, or a wrong --api-host can return an HTML page with status 200. The SDK turned the page into empty models, and each command then stopped with an unexpected error and sent an error report. The REST client now rejects a 2xx HTML response with an API error, so commands show the normal "Failed to ..." message and exit with code 1. Fixes CLOUDSMITH-CLI-D Fixes CLOUDSMITH-CLI-F Fixes CLOUDSMITH-CLI-N Fixes CLOUDSMITH-CLI-W Fixes CLOUDSMITH-CLI-V Fixes CLOUDSMITH-CLI-A Fixes CLOUDSMITH-CLI-T Fixes CLOUDSMITH-CLI-S Fixes CLOUDSMITH-CLI-Q Fixes CLOUDSMITH-CLI-P Fixes CLOUDSMITH-CLI-R Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Non-UTF-8 HTML bodies can raise a decoding exception before validation, bypassing the intended API error handling.
1 open issue
What changed in this PR
This PR adds HTML-response validation to the shared REST client so API commands report normal API errors when a proxy, captive portal, or incorrect API host returns an HTML page.
Changes:
- Reject successful
text/htmlresponses with a status-0 API error. - Add REST-client and entitlements CLI regression tests.
- Document the corrected error behavior in the changelog.
| File | Description |
|---|---|
cloudsmith_cli/core/tests/test_rest.py |
Tests rejection of a successful HTML response. |
cloudsmith_cli/core/rest.py |
Adds shared HTML content-type validation. |
cloudsmith_cli/cli/tests/commands/test_entitlements.py |
Tests normal CLI error handling for HTML responses. |
CHANGELOG.md |
Documents the HTML-response handling fix. |
Review effort: Balanced
| if not 200 <= rest_resp.status <= 299: | ||
| raise ApiException(http_resp=rest_resp) | ||
|
|
||
| _raise_for_html(rest_resp) |
This branch has not been deployed
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.

Description
Sometimes the API host answers with an HTML page and status 200. This happens with a TLS-intercepting proxy login page, a captive portal, or an
--api-hostthat points to a website. The REST client accepted any 2xx body. The SDK then turned the HTML into empty models, and each command failed somewhere different with an unexpected error that also went to Sentry.The REST client now rejects a 2xx response with a
text/htmlcontent type. It raises the same status-0 API error that connection failures use, so every command goes through its normal error handling. The v2 client (metadata list, workspace domains) uses the same REST client, so it gets the fix too.Before:
After:
I checked these commands against a local server that returns an HTML page. Each one now prints its "Failed to ..." or "Could not ..." message, exits with code 1, and sends no error report:
entitlements list,list distros,metrics entitlements,metrics packages,check rates,check service,tokens list,whoami --verbose,list dependencies,tags list,metadata list, andquota history.Fixes Sentry issues CLOUDSMITH-CLI-D, -F, -N, -W, -V, -A, -T, -S, -Q, -P, and -R.
Type of Change
Additional Notes
text/html. A JSON API never sends that type, so no endpoint that works today can break. A portal that sends HTML astext/plainor with no content type still gets through. A check for "not JSON" would cover that, but it is a larger change in a shared client.RestClient.request. This change adds one call after the status check and a new helper at the end of the file, so the two PRs do not touch the same lines.🤖 Generated with Claude Code