Skip to content

fix: handle non-JSON text/plain and text/html API responses#1428

Draft
jayy-77 wants to merge 1 commit intoCrowdStrike:devfrom
jayy-77:fix/text-plain-response-handling-1154
Draft

fix: handle non-JSON text/plain and text/html API responses#1428
jayy-77 wants to merge 1 commit intoCrowdStrike:devfrom
jayy-77:fix/text-plain-response-handling-1154

Conversation

@jayy-77
Copy link

@jayy-77 jayy-77 commented Feb 11, 2026

Summary

Fixes #1154 — When the API returns a text/plain response with non-JSON content (e.g., a 403 with Remote response feature is not enabled), the SDK now correctly surfaces the actual error text instead of replacing it with a generic No content was received message.

Changes

  • src/falconpy/_util/_functions.py:

    • Added _build_text_error_body() helper to wrap raw text in the standard CrowdStrike error format
    • Fixed calc_content_return() text/plain handler to try JSON parsing first (backward compat), then fall back to the structured error body
    • Added text/html handler for proxy/WAF error pages
    • Added text/html branch to log_api_activity() so HTML responses are logged as text
  • tests/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

  • All code paths covered by unit testing
  • No new linting errors introduced
  • 18/18 tests pass

…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
@jayy-77 jayy-77 force-pushed the fix/text-plain-response-handling-1154 branch from e2caa48 to 2f33137 Compare February 11, 2026 21:36
@jshcodes jshcodes added python Pull requests that update Python code or general Python related questions API usage General API usage issues and questions unit testing Pull requests that include unit testing updates labels Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API usage General API usage issues and questions python Pull requests that update Python code or general Python related questions unit testing Pull requests that include unit testing updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants