Treat 404 as auth error and persist refreshed tokens #1
Reference in New Issue
Block a user
Delete Branch "fix/token-refresh-404"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
After running for some time, the integration begins failing with
404errors against the DKN Cloud NA API and stops recovering. Root causes:404is not treated as an auth error. The DKN Cloud NA API appears to return404(not401) for expired tokens. The previousauth_error_statuses={401, 403}let those 404s fall through to a genericDknConnectionError, so the coordinator just loggedUpdateFailedand kept retrying with the stale token — never triggering a token refresh or reauth.refresh_access_token()stored new tokens only on the in-memory client. On Home Assistant restart we reloaded the old (now-expired) tokens from the config entry, and eventually the in-memory refresh token would expire too.Changes
404toauth_error_statusesonis_logged_in,refresh_access_token, andfetch_installationsso expired-token 404s trigger the refresh + reauth flow.entry.optionsafter each successful coordinator update.scan_interval,expose_pii) still trigger a reload as before.status >= 400atWARNING(with body) and logINFOwhen a token refresh is attempted, so failures are diagnosable without enabling debug logging.Test plan
DKN token expired, attempting refreshfollowed by normal polling, with noUpdateFailed.