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
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
"dev:compose-api": "VITE_API_URL=http://localhost:13000/api/v1 vite",
|
||||||
"build": "tsc -b && vite build",
|
"build": "tsc -b && vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"storybook": "storybook dev -p 6006",
|
"storybook": "storybook dev -p 6006",
|
||||||
|
|||||||
@@ -37,11 +37,14 @@ export function ScenariosPage() {
|
|||||||
const load = useCallback(() => {
|
const load = useCallback(() => {
|
||||||
Promise.all([scenarios.list(), environments.list(1, 200)])
|
Promise.all([scenarios.list(), environments.list(1, 200)])
|
||||||
.then(([scenarioRes, envRes]) => {
|
.then(([scenarioRes, envRes]) => {
|
||||||
setItems(scenarioRes.data);
|
setItems(scenarioRes?.data ?? []);
|
||||||
setEnvs(envRes.data);
|
setEnvs(envRes?.data ?? []);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
toast.error((err as Error).message);
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, []);
|
}, [toast]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
load();
|
load();
|
||||||
|
|||||||
Reference in New Issue
Block a user