Skip to content

Distinguish transient API errors from authentication failures - #92

Merged
jnimmo merged 1 commit into
masterfrom
claude/dazzling-albattani-0azu0b
Aug 24, 2026
Merged

jnimmo merged 1 commit into
masterfrom
claude/dazzling-albattani-0azu0b

Conversation

@jnimmo

@jnimmo jnimmo commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Summary

This PR improves error handling in the IntesisHome controller to distinguish between transient API errors and permanent authentication failures. Previously, all API errors were treated as authentication failures, which would retire the poller permanently and leave the controller unavailable until restart. Now, only errors with specific error codes known to indicate credential rejection are treated as authentication failures.

Key Changes

  • Added AUTH_ERROR_CODES constant in intesishome.py to define which error codes represent credential rejection (currently only code 3 / WRONG_USERNAME_PASSWORD)

  • Implemented _raise_api_error() method that classifies API errors based on their error code:

    • Known authentication error codes raise IHAuthenticationError and set _authentication_failed flag
    • Unknown/transient error codes raise IHConnectionError and allow the poller to continue retrying
    • Defaults to treating unknown codes as transient (safer than incorrectly retiring the poller)
  • Added _authentication_failed property to IntesisBase to track when credentials are rejected

    • Exposed via public authentication_failed property for consumers to detect auth failures
    • Causes is_available to return False until credentials are fixed
  • Updated poller logic to:

    • Clear _authentication_failed flag on successful polls (credentials may have been restored)
    • Only retire the poller on IHAuthenticationError, not on transient connection errors
    • Log appropriate warnings for transient errors vs. errors for credential rejection
  • Added comprehensive test coverage for:

    • Transient errors not retiring the poller
    • Credential rejection being reported as authentication failure
    • Successful polls clearing earlier authentication failures
    • Credential rejection retiring the poller
    • Error classification based on code, not message text
  • Version bump from 2.4.0 to 2.5.0

Implementation Details

The error classification is deliberately asymmetric: unknown error codes default to transient rather than authentication failures. This is because the full error code table is not published, and incorrectly retiring the poller (guessing auth) is more expensive than retrying on a transient error (guessing transient). Unknown codes are logged so they can be added to AUTH_ERROR_CODES once their meaning is confirmed.

https://claude.ai/code/session_01AQwFhbWXYx7gU9Zswip8eV

The cloud API reports every failure the same way - HTTP 200 carrying an
errorCode - and poll_status treated all of them as IHAuthenticationError.
The poller retires on that, permanently, so a single transient error from
the backend killed state refresh for the life of the process. State then
sat frozen until the consumer restarted, with nothing in the library
saying why.

Classify on the code instead. /api.php/get/control answers a bad password
with {"errorCode": 3, "errorMessage": "WRONG_USERNAME_PASSWORD"}, so 3
raises IHAuthenticationError and everything else raises IHConnectionError,
which the poller already rides out. The rest of the table is not
published, so unknown codes default to transient and log the number they
saw: guessing transient costs one poll interval, guessing auth costs a
controller that has stopped polling for good, and adding a code once its
meaning is known is a one-line change.

Genuine credential failures still retire the poller - there is no point
hammering the API with a password it has rejected - but they now set
authentication_failed, so a consumer can tell "unavailable, retrying"
apart from "unavailable, needs you". is_available reports false while the
flag is set, since cached state inside the staleness window is no longer
going to be refreshed by anything. A poll that gets through clears it.
@jnimmo
jnimmo merged commit 9853be5 into master Aug 24, 2026
12 checks passed
@jnimmo
jnimmo deleted the claude/dazzling-albattani-0azu0b branch August 24, 2026 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants