From cb8007074e659ea304c7332ec5afa45e9f0d5bd1 Mon Sep 17 00:00:00 2001 From: space Date: Sun, 1 Mar 2026 15:10:57 +0100 Subject: [PATCH] feat: add error handling for state fetching in App component --- functions/control/main.py | 4 +++- tv/src/App.tsx | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/functions/control/main.py b/functions/control/main.py index 639f0f6..76b7522 100644 --- a/functions/control/main.py +++ b/functions/control/main.py @@ -3,6 +3,8 @@ import io import json import time from minio import Minio +import redis +import os DEFAULT_STATE = { "text": { @@ -27,7 +29,7 @@ MINIO_CLIENT = Minio( secure=True, ) BUCKET = "tv-control" - +r = redis.Redis(host='194.15.36.205',username="default", port=12004, db=12, password=os.getenv("REDIS")) def _read_state(): try: with open("/app/state.json", "r") as f: diff --git a/tv/src/App.tsx b/tv/src/App.tsx index 1feeb8b..be87b22 100644 --- a/tv/src/App.tsx +++ b/tv/src/App.tsx @@ -64,6 +64,7 @@ function App() { const [imagePopup, setImagePopup] = useState({ showing: false, image_url: "", caption: "" }); const [dataCards, setDataCards] = useState([]); const [settings, setSettings] = useState({ background_url: "" }); + const [fetchError, setFetchError] = useState(false); useEffect(() => { const handleFullscreenChange = () => { @@ -86,9 +87,11 @@ function App() { setImagePopup(state.image_popup ?? { showing: false, image_url: "", caption: "" }); setDataCards(state.data_cards ?? []); setSettings(state.settings ?? { background_url: "" }); + setFetchError(false); }) .catch((error) => { console.error("Error pulling state:", error); + setFetchError(true); }); }; @@ -113,6 +116,13 @@ function App() { return (
+ {fetchError && ( +
+ ! +

Connection failed

+

Retrying every 5 seconds…

+
+ )} {settings.background_url && (