Repository navigation
fix(client): carry HTTP status and error body into InferenceGatewayAPIError - #139
Conversation
|
@infer Can you resolve the merge conflict? |
|
Model: Todos
Pull Request✅ Infer Result: SuccessAll done - the working tree is clean, the branch is in sync, and GitHub reports PR #139 as MERGEABLE. Final todo update: Merge conflict resolved - PR #139 now reports What the conflict wasMain advanced with PR #138 ( How it was resolved
One note: the PR description's "Tests run: 47 passed" is now 50 passed (main's three new tests are included); happy to update the body if wanted. Model: Tokens: 3,669,193 in · 46,249 out · 3,715,442 total (43 requests) Tool calls: 74 total · 100% success rate TracesStatsTriggered by edenreich · Infer Action · OSS |
…IError
requests.Response.__bool__ returns self.ok, so every 4xx/5xx response is falsy and _make_request always fell back to status_code=0/response_data={}.
Streaming methods now also populate status_code/response_data (reading the error body first on httpx) and wrap connection failures from session.post / client.stream as InferenceGatewayError on both backends.
08a09f2 to
1840afa
Compare
## [0.21.1](v0.21.0...v0.21.1) (2026-09-26) ### 🐛 Bug Fixes * **client:** carry HTTP status and error body into InferenceGatewayAPIError ([#139](#139)) ([d58a54f](d58a54f)) * **client:** close requests Session in close() and apply timeout to streaming calls ([#138](#138)) ([4a1e48f](4a1e48f)) * **client:** route health_check and proxy_request to root-level routes ([#136](#136)) ([ec782ca](ec782ca)) ### 📚 Documentation * **readme:** correct MCP_ENABLED env var, provider list, vision reference, and images example ([#137](#137)) ([8cc2ef6](8cc2ef6)) * **readme:** document streaming error behavior parity ([#140](#140)) ([23a1d69](23a1d69)) ### 🔧 Miscellaneous * **deps:** bump claude-code 2.1.278 -> 2.1.280 ([#130](#130)) ([2a73e16](2a73e16)) * **deps:** bump infer CLI v0.205.3 -> v0.208.0 ([#131](#131)) ([703f184](703f184))
|
🎉 This PR is included in version 0.21.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Resolves #132
Summary
With the default
requestsbackend, every HTTP error surfaced asInferenceGatewayAPIErrorwithstatus_code=0andresponse_data={},breaking the README "Error Handling" contract. The root cause: the error
handler tested response truthiness, and
requests.Response.__bool__returns
self.ok, which isFalsefor every 4xx/5xx response. The threestreaming methods had the same gap on both backends and additionally let
connection failures escape as raw
requests/httpxexceptions instead ofInferenceGatewayError.Changes
InferenceGatewayClient._api_error()helper builds the API errorfrom the response using
response is not None(not truthiness), so thereal HTTP status and parsed JSON error body are carried on both
backends; non-JSON bodies fall back to
{}._make_requestuses the helper, preserving existing fallback behaviorwhen no response object exists.
create_chat_completion_stream,create_response_stream,create_message_stream) now:InferenceGatewayAPIErrorwithstatus_codeandresponse_data(httpx error bodies are read viaresponse.read()inside the stream context before parsing);
self.session.post(...)/self.client.stream(...)asInferenceGatewayError, matchingnon-streaming behavior.
requests.Responseobjects (Mock is always truthy, which hid the bug) covering
non-streaming and streaming on both backends, plus non-JSON error
bodies and connection failures; the synthetic
Exception("API Error")stream scenario now uses a realisticrequests.exceptions.ConnectionError.Tests run:
task lint(black, isort, mypy) andtask test- 47 passed,1 xfailed (pre-existing, unrelated).
no docs ticket: the README already documents this behavior; this PR
makes the SDK honor it. No schemas/models changes.