Duplicated owner/forwarder branching across 4 endpoints in app.py #18
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
paul_loth/krautspaceTV#18
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Problem
Four endpoints in
backend/app.pyeach repeat the same "if this process is the rotation owner, handle locally; otherwise forward to the owner over loopback HTTP, swallowinghttpx.HTTPError" branch:slide_current(line 115-129)slide_visible(line 132-141)report_slide_visible(line 144-157)view_now(line 322-332)Each copy re-implements the same
httpx.AsyncClient(timeout=5)+ try/except pattern with slightly different request shapes (GET vs POST, query params vs none, different fallback payloads on failure). This is easy to get subtly inconsistent as more owner-forwarded endpoints get added (e.g. a future one might forget the try/except, or use a different timeout).Suggested fix
Extract a small helper, e.g.:
and have each forwarding branch call it, handling the per-endpoint fallback response shape at the call site. Reduces the duplicated branching from 4 copies to 1.
Where
backend/app.py:115-157,backend/app.py:322-332Fixed and deployed. Extracted
_forward_to_owner(method, path, **kwargs)in backend/app.py and switched all 4 owner/forwarder endpoints (slide_current, slide_visible, report_slide_visible, view_now) to use it — same requests/fallback behavior, one shared implementation instead of four copies.