Repository navigation
feat(exceptions): classify DimplexApiError as transient (5xx/429) or hard (4xx) - #125
Merged
Merged
Conversation
DimplexApiError carried only status and message, so once client.py exhausted its internal retries a caller could not tell an exhausted 5xx/429 (transient -- back off and keep going) from a hard 4xx (surface it). DimplexAuthError already has this structure; API errors did not. Add keyword-only transient (default False) and code to DimplexApiError, keeping the positional (status, message) signature so existing call sites are unchanged. The two raise sites in client.py set transient from _RETRYABLE_STATUS membership (429/5xx), the same set that drives the retry loop, so the classification has a single source of truth. Documents the attribute in the README and api-reference. Closes #122
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
DimplexApiErrorcarried onlystatusandmessage, so onceclient.pyexhausted its internal retries a caller couldn't tell an exhausted 5xx/429 (transient — back off and keep going) from a hard 4xx (surface it).DimplexAuthErroralready has this classification; API errors didn't. Closes #122.Adds keyword-only
transient(defaultFalse) andcodetoDimplexApiError, keeping the positional(status, message)signature so every existing call site is unchanged. The two raise sites inclient.pysettransientfrom_RETRYABLE_STATUSmembership (429/5xx) — the same set that drives the retry loop, so the classification has a single source of truth inclient.pyrather than duplicating the status list in the exception.Type of change
Checklist
ruff check+ruff formatpassmypystrict passes (9 source files, no# type: ignore)pytestpasses and new behaviour is covered (200 passed; 2 new tests assert 5xx→transient=True, 4xx→transient=False, verified to fail against pristinemainwithAttributeError)docs/api-reference.mdupdated with the new attributeBehaviour changes worth calling out
Additive only.
DimplexApiError(status, message)still works unchanged;transientdefaults toFalse. A consumer (e.g. the Home Assistant coordinator) can now checkerr.transientto back off on a retried-and-failed 5xx/429 instead of surfacing it like a hard 4xx.