feat: raise TM1pyNetworkException for HTML/Cloudflare responses#1415
Conversation
- Added TM1pyNetworkException to handle upstream HTML/WAF/Cloudflare error pages - Updated RestService.verify_response to detect non-JSON HTML responses - Added comprehensive unit tests for exception behaviour and verify_response integration
|
Hi @jamestwilkinson - thanks for working on this, I agree that is much needed as we don't have dedicated network exceptions.
Please let me know your thoughts. |
- Merge exception imports onto single line using package path in RestService.py - Add TM1pyNetworkException to retry loop alongside TM1pyRestException - Add headers paramater to _extract_cloudflare_ray_id to first check CF-RAY header
|
Hi @nicolasbisurgi, thanks for the review. I've addressed the points raised and pushed the updated code. Thanks, James. |
- Export TM1pyVersionDeprecationException from TM1py.Exceptions (the package-path import in RestService introduced in the prior commit referenced a name that was never exported, breaking `import TM1py`) - Broaden HTML detection: case-insensitive, also match bare <html> - Type hints: Optional[str] for _extract_cloudflare_ray_id and ray_id - Document the intentional non-subclassing of TM1pyRestException - Add regression tests: JSON error still raises TM1pyRestException, isolate each HTML detection branch, OK response raises nothing - Cleanup: trailing whitespace, missing EOF newlines, import sorting Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thanks @jamestwilkinson ! The rest is all tidy-up coming from ruff and other linter:
All 20 tests pass and Let me know if you are ok with these changes and then we can merge it. |
|
Thanks @nicolasbisurgi, please go ahead by all means. Kind regards, James. |
Collapse multi-line exception calls and fix blank-line/comment whitespace to satisfy the PR-validation black --check step. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
PR: Raise TM1pyNetworkException for HTML / Cloudflare responses
Summary
This PR adds a new exception type, TM1pyNetworkException, to handle network/WAF/Cloudflare HTML error pages that are not valid TM1 REST responses, and misleading as TM1 has not received any message. These responses previously caused TM1pyRestException to be raised with confusing error messages.
Problem
When TM1 is fronted by Cloudflare, load balancers, proxies, or WAFs, upstream failures often return HTML pages, not JSON.
RestService.verify_response attempted to parse these as TM1 REST errors, resulting in:
This behaviour is tracked in Issue #1393.
Solution
Updated RestService.verify_response:
Added unit tests:
Impact
Fixes
Fixes #1393