From 6c43b53590220f68c11e4f7c01a48fb13b5b1067 Mon Sep 17 00:00:00 2001 From: Andrii Arsenin Date: Tue, 14 Apr 2026 23:09:38 +0300 Subject: [PATCH] fix(scenarios): add error handling for API calls and dev script with local API - add catch handler to promises for better error visibility - use null coalescing operators to prevent undefined accessing - add dev:compose-api npm script pointing to localhost:13000 API - include toast dependency in useCallback to avoid stale closures --- client/package.json | 1 + client/src/pages/scenario/ScenariosPage.tsx | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client/package.json b/client/package.json index fab3062..348c461 100644 --- a/client/package.json +++ b/client/package.json @@ -4,6 +4,7 @@ "type": "module", "scripts": { "dev": "vite", + "dev:compose-api": "VITE_API_URL=http://localhost:13000/api/v1 vite", "build": "tsc -b && vite build", "preview": "vite preview", "storybook": "storybook dev -p 6006", diff --git a/client/src/pages/scenario/ScenariosPage.tsx b/client/src/pages/scenario/ScenariosPage.tsx index 1481767..f976d13 100644 --- a/client/src/pages/scenario/ScenariosPage.tsx +++ b/client/src/pages/scenario/ScenariosPage.tsx @@ -37,11 +37,14 @@ export function ScenariosPage() { const load = useCallback(() => { Promise.all([scenarios.list(), environments.list(1, 200)]) .then(([scenarioRes, envRes]) => { - setItems(scenarioRes.data); - setEnvs(envRes.data); + setItems(scenarioRes?.data ?? []); + setEnvs(envRes?.data ?? []); + }) + .catch((err) => { + toast.error((err as Error).message); }) .finally(() => setLoading(false)); - }, []); + }, [toast]); useEffect(() => { load();