Skip to content

fix: handle non-JSON error responses from API gateway#741

Merged
CFenner merged 1 commit intoopenviess:masterfrom
lackas:fix/non-json-error-response
Apr 16, 2026
Merged

fix: handle non-JSON error responses from API gateway#741
CFenner merged 1 commit intoopenviess:masterfrom
lackas:fix/non-json-error-response

Conversation

@lackas
Copy link
Copy Markdown
Contributor

@lackas lackas commented Apr 16, 2026

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 raises ContentTypeError. Now we check the response content type before parsing.

2. TIMEOUT errors in extendedPayload
The API sometimes returns {'extendedPayload': {'code': '500', 'reason': 'TIMEOUT'}} with empty errorType and no statusCode. This slipped through all existing error handlers and caused PyViCareInvalidDataError ("Missing 'data' property") instead of PyViCareInternalServerError — bypassing the stale-cache fallback.

3. Connection-level errors (DNS timeout, connection refused)
Network errors raise OSError before 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).

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)
@lackas lackas force-pushed the fix/non-json-error-response branch from c566e38 to e857782 Compare April 16, 2026 03:46
@CFenner CFenner added the bugfix label Apr 16, 2026
Copy link
Copy Markdown
Member

@CFenner CFenner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@CFenner CFenner merged commit c4fe4a2 into openviess:master Apr 16, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants