Repository navigation
fix: Handle server errors in Brandt login - #2305
Merged
Merged
Conversation
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.
…er-errors # Conflicts: # tests/test_auth.py
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.
BrandtAuthStrategy.login()treated every status >= 400 from the middlewaresessions.jsoncall 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 rawaiohttp.ContentTypeError, because it is not aValueError.Changes:
sessions.jsonandprofile/jwt.jsonnow call_raise_for_server_errorfirst, like the Cozytouch and Somfy strategies, so 5xx raisesServiceUnavailableError/MaintenanceError.sessions.jsonerror body is read with_json_body, so a non-JSON 4xx still raisesBrandtBadCredentialsError. The firsterrorentry is still used as the message.sessions.json, a non-JSON 401, and a 503 fromjwt.json.This also affects the upcoming Sauter Smart Control realm (#2304), which uses the same middleware login.