Distinguish transient API errors from authentication failures - #92
Merged
Merged
Conversation
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.
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.
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_CODESconstant inintesishome.pyto 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:IHAuthenticationErrorand set_authentication_failedflagIHConnectionErrorand allow the poller to continue retryingAdded
_authentication_failedproperty toIntesisBaseto track when credentials are rejectedauthentication_failedproperty for consumers to detect auth failuresis_availableto returnFalseuntil credentials are fixedUpdated poller logic to:
_authentication_failedflag on successful polls (credentials may have been restored)IHAuthenticationError, not on transient connection errorsAdded comprehensive test coverage for:
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_CODESonce their meaning is confirmed.https://claude.ai/code/session_01AQwFhbWXYx7gU9Zswip8eV