fix: handle non-JSON error responses from API gateway#741
Merged
CFenner merged 1 commit intoopenviess:masterfrom Apr 16, 2026
Merged
fix: handle non-JSON error responses from API gateway#741CFenner merged 1 commit intoopenviess:masterfrom
CFenner merged 1 commit intoopenviess:masterfrom
Conversation
Wrap three types of transient API errors as PyViCareInternalServerError so the cached service can fall back to stale data instead of crashing with full tracebacks in the HA logs: 1. Non-JSON 5xx responses (e.g. 502 HTML from load balancer) 2. TIMEOUT errors in extendedPayload (empty errorType, no statusCode) 3. Connection-level errors (DNS timeout, connection refused)
c566e38 to
e857782
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.
When the Viessmann API has issues (maintenance, overload, DNS problems), several error types propagate as unhandled exceptions with full tracebacks in the Home Assistant logs. All of these should be caught so the cached service can fall back to stale data instead of crashing.
This PR fixes three scenarios:
1. Non-JSON 5xx responses (e.g. 502 HTML from load balancer)
Calling
.json()on an HTML error page raisesContentTypeError. Now we check the response content type before parsing.2. TIMEOUT errors in
extendedPayloadThe API sometimes returns
{'extendedPayload': {'code': '500', 'reason': 'TIMEOUT'}}with emptyerrorTypeand nostatusCode. This slipped through all existing error handlers and causedPyViCareInvalidDataError("Missing 'data' property") instead ofPyViCareInternalServerError— bypassing the stale-cache fallback.3. Connection-level errors (DNS timeout, connection refused)
Network errors raise
OSErrorbefore any HTTP response exists, bypassing all error handlers entirely.All three are now wrapped as
PyViCareInternalServerError, which the cached service already handles gracefully (returns stale data + logs a warning).