Duplicated is_available/render boilerplate across slide types #9
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#9
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
`backend/slides/mastodon.py`, `matrix.py`, and `train.py` each independently implement near-identical `is_available()`/`render()` pairs: open an `httpx.AsyncClient(timeout=3.0)`, GET a URL, catch `httpx.HTTPError`, return a "Unable to load ..." fallback `
This is a fair amount of copy-pasted control flow for what's conceptually "fetch JSON from a URL, render a fallback on failure."
Suggested fix
Factor the common "fetch with timeout, catch HTTPError, return fallback HTML on failure" pattern into a small shared helper in `backend/slides/registry.py` (or a new `_http.py`), and have the four slide types call it. Not urgent — the current duplication is small and easy to follow — but worth doing before adding a 5th similar slide type.
Fixed in
5f58e3e(merged to main at103cdf2): added backend/slides/_http.py with shared fetch_json()/url_ok() helpers; mastodon.py, matrix.py, and train.py now use them instead of each hand-rolling their own httpx try/except block. Same URLs, headers, and fallback HTML preserved.