fix: handle non-JSON text/plain and text/html API responses#1428
Draft
jayy-77 wants to merge 1 commit intoCrowdStrike:devfrom
Draft
fix: handle non-JSON text/plain and text/html API responses#1428jayy-77 wants to merge 1 commit intoCrowdStrike:devfrom
jayy-77 wants to merge 1 commit intoCrowdStrike:devfrom
Conversation
…ike#1154) When the CrowdStrike API returns a text/plain response containing non-JSON content (e.g. a 403 with 'Remote response feature is not enabled'), calc_content_return() previously called json.loads() which crashed with JSONDecodeError. The error was caught upstream and replaced with a generic 'No content was received' message, masking the actual API error. Modified source files (5): - src/falconpy/_util/_functions.py: Add _build_text_error_body() helper, fix text/plain handler with JSON-first fallback, add text/html handler, fix log_api_activity for text/html - src/falconpy/_error/_warnings.py: Enhance NoContentWarning with response_body and content_type properties to preserve raw error text - src/falconpy/_result/_result.py: Add _is_text_error_body() static method and dedicated _parse_body path for text error bodies - src/falconpy/_util/__init__.py: Export _build_text_error_body - src/falconpy/api_complete/_legacy.py: Import _build_text_error_body, add robust error extraction in authenticate() Tests: 31 edge-case unit tests in tests/test_response_handling.py
e2caa48 to
2f33137
Compare
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.
Summary
Fixes #1154 — When the API returns a
text/plainresponse with non-JSON content (e.g., a 403 withRemote response feature is not enabled), the SDK now correctly surfaces the actual error text instead of replacing it with a genericNo content was receivedmessage.Changes
src/falconpy/_util/_functions.py:_build_text_error_body()helper to wrap raw text in the standard CrowdStrike error formatcalc_content_return()text/plain handler to try JSON parsing first (backward compat), then fall back to the structured error bodytext/htmlhandler for proxy/WAF error pagestext/htmlbranch tolog_api_activity()so HTML responses are logged as texttests/test_response_handling.py(NEW): 18 edge-case unit tests covering:Is this a breaking change?
No — existing text/plain JSON responses continue to parse identically. Only non-JSON text responses change behavior (from crash → structured result).
Checklist