Skip to content

fix: Handle server errors in Brandt login - #2305

Merged
iMicknl merged 2 commits into
mainfrom
fix/brandt-login-server-errors
Oct 24, 2026
Merged

iMicknl merged 2 commits into
mainfrom
fix/brandt-login-server-errors

Conversation

@iMicknl

@iMicknl iMicknl commented Oct 24, 2026

Copy link
Copy Markdown
Owner

BrandtAuthStrategy.login() treated every status >= 400 from the middleware sessions.json call as bad credentials, including 5xx. During a Brandt middleware outage, Home Assistant would therefore ask the user to reauthenticate instead of retrying. A non-JSON error body (for example an HTML page from a proxy) also leaked a raw aiohttp.ContentTypeError, because it is not a ValueError.

Changes:

  • sessions.json and profile/jwt.json now call _raise_for_server_error first, like the Cozytouch and Somfy strategies, so 5xx raises ServiceUnavailableError / MaintenanceError.
  • The sessions.json error body is read with _json_body, so a non-JSON 4xx still raises BrandtBadCredentialsError. The first error entry is still used as the message.
  • Added tests for a 503 from sessions.json, a non-JSON 401, and a 503 from jwt.json.

This also affects the upcoming Sauter Smart Control realm (#2304), which uses the same middleware login.

Route 5xx from the Brandt middleware sessions.json and profile/jwt.json
calls through _raise_for_server_error so outages raise
ServiceUnavailableError instead of BrandtBadCredentialsError or
BrandtServiceError. Parse the sessions.json error body with _json_body so
a non-JSON 4xx no longer leaks aiohttp.ContentTypeError.
@github-actions github-actions Bot added the bug Something isn't working label Oct 24, 2026
@iMicknl
iMicknl marked this pull request as ready for review October 24, 2026 14:48
@iMicknl
iMicknl requested a review from tetienne as a code owner October 24, 2026 14:48
Copilot AI balanced review requested due to automatic review settings October 24, 2026 14:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@iMicknl
iMicknl merged commit 8e16863 into main Oct 24, 2026
11 checks passed
@iMicknl
iMicknl deleted the fix/brandt-login-server-errors branch October 24, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants