Problem
REST error handling depends on parsing exception message text.
src/haclient/infra/rest_aiohttp.py:131-133 converts every non-401 HTTP error into a generic HAClientError string. get_state() then detects missing entities by checking whether "HTTP 404" appears in str(err) at src/haclient/infra/rest_aiohttp.py:186-190.
That is brittle. If the message format changes, or another error body happens to include that text, get_state() behavior changes.
Suggested Fix
Introduce a structured HTTP exception, for example HTTPError(status: int, method: str, path: str, body: str), derived from HAClientError.
Then:
- Raise
HTTPError from _request() for HTTP failures.
- Check
err.status == 404 in get_state().
- Keep authentication mapped to
AuthenticationError.
- Add tests that
get_state() returns None only for real 404 responses.
Rationale
Status codes are structured data. Encoding them into strings and parsing them back out is avoidable fragility in a reliability-sensitive client.
Problem
REST error handling depends on parsing exception message text.
src/haclient/infra/rest_aiohttp.py:131-133converts every non-401 HTTP error into a genericHAClientErrorstring.get_state()then detects missing entities by checking whether"HTTP 404"appears instr(err)atsrc/haclient/infra/rest_aiohttp.py:186-190.That is brittle. If the message format changes, or another error body happens to include that text,
get_state()behavior changes.Suggested Fix
Introduce a structured HTTP exception, for example
HTTPError(status: int, method: str, path: str, body: str), derived fromHAClientError.Then:
HTTPErrorfrom_request()for HTTP failures.err.status == 404inget_state().AuthenticationError.get_state()returnsNoneonly for real 404 responses.Rationale
Status codes are structured data. Encoding them into strings and parsing them back out is avoidable fragility in a reliability-sensitive client.