Repository navigation
Raise GlpiProtocolError when a success response body is not JSON - #52
Merged
Merged
Conversation
…onse body is not JSON, instead of a bare json.JSONDecodeError. Every decode of a success body on the v2 transport, the v1 session and the token manager goes through decode_json_body. It carries the status, URL, content type, body length and a bounded excerpt, chains the decode error, and is not retried. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…helpers, which now raise the same error for a non-empty body that is not JSON. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and the docs give the error excerpt in bytes, not characters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #52 +/- ##
==========================================
+ Coverage 98.11% 98.13% +0.01%
==========================================
Files 97 97
Lines 3875 3908 +33
==========================================
+ Hits 3802 3835 +33
Misses 73 73 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Nov 23, 2026
Merged
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.
Problem
When a server or a proxy answered a request with status 200 but a body that is not JSON (an HTML error page, a truncated or garbled answer), the client let
json.JSONDecodeErrorescape. That is a bareValueError, so a caller could not tell it from a refused argument, and it carried no response facts.Fix
GlpiResponseBodyError, a subclass ofGlpiProtocolError, exported from the package root. It carriesstatus_code,url,content_type,body_lengthand a boundedbody_excerpt. The body is kept out of the message, and the decode error is chained as__cause__.decode_json_body: the v2 transport, the v1 session and the OAuth token manager.DELETE, v1 calls without a payload) is unchanged. An empty 200 on a route that must return JSON raises the new error.response_json_or_emptyandresponse_json_mappingstill read an empty or whitespace-only body as empty, but now raise the new error for a non-empty body that is not JSON.GlpiProtocolErroris aValueErrorsubclass, like the error it replaces, so existingexcept ValueErrorhandlers still catch it.Tests
On both trees:
decode_json_body:Locally,
ruff check,mypy glpi_python_client,unasync_build.py --checkand the sphinx-Wbuild pass, and so do the test files this branch touches (227 passed). The full suite and the coverage gate run in CI.Overlaps with other open PRs
This PR only conflicts with the other open PRs (#50, #51, #53) in
CHANGELOG.md: keep both entries.Suggested merge order: #50, #51, #52, #53. After each merge I rebase the next branch: the conflicts are the
CHANGELOG.mdentries, plus one import line in_v1_session.pyfor #51.🤖 Generated with Claude Code