Skip to content

Commit 702786e

Browse files
Xaohssvenvandescheur
authored andcommitted
🥅 [#223] fix: handling error better for catalogi api
1 parent df0f870 commit 702786e

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

frontend/src/App.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
H2,
66
Hr,
77
Logo,
8-
ModalService,
98
Outline,
109
Select,
1110
} from "@maykin-ui/admin-ui";
@@ -172,15 +171,13 @@ function App() {
172171
sidebarItems={sidebarItems}
173172
grid={!hideUi}
174173
>
175-
<ModalService>
176-
<ConfigContext.Provider
177-
value={{ templatesContentOnly: true, templatesGrid: false }}
178-
>
179-
<OBContext.Provider value={{ catalogiChoices }}>
180-
<Outlet />
181-
</OBContext.Provider>
182-
</ConfigContext.Provider>
183-
</ModalService>
174+
<ConfigContext.Provider
175+
value={{ templatesContentOnly: true, templatesGrid: false }}
176+
>
177+
<OBContext.Provider value={{ catalogiChoices }}>
178+
<Outlet />
179+
</OBContext.Provider>
180+
</ConfigContext.Provider>
184181
</BaseTemplate>
185182
);
186183
}

frontend/src/hooks/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export * from "./useBreadcrumbItems";
2-
export * from "./useCatalogi";
2+
export * from "./useCatalogi.tsx";
33
export * from "./useChildRoutes";
44
export * from "./useCombinedSearchParams";
55
export * from "./useCurrentMatch";
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Errors, useAlert } from "@maykin-ui/admin-ui";
12
import { cacheGet, cacheSet } from "@maykin-ui/client-common";
23
import { useEffect, useState } from "react";
34
import { useNavigate, useParams } from "react-router";
@@ -19,6 +20,7 @@ export function useCatalogi(
1920
const [catalogiChoices, setCatalogiChoices] = useState<
2021
components["schemas"]["OBOption_str_"][]
2122
>([]);
23+
const alert = useAlert();
2224

2325
const handleCatalogusChange = (newCatalogusId: string) => {
2426
if (newCatalogusId) {
@@ -57,7 +59,15 @@ export function useCatalogi(
5759
}
5860
}
5961
} catch (error) {
60-
console.error("Failed to fetch catalogi choices:", error);
62+
const messages: string[] = ["Failed to fetch catalogi choices."];
63+
if (error instanceof Response) {
64+
messages.push(`Status: ${error.status}, ${error.statusText}`);
65+
}
66+
alert(
67+
"Foutmelding",
68+
(<Errors errors={messages} />) as unknown as string, // TODO: Fix in admin-ui
69+
"Ok",
70+
);
6171
}
6272
};
6373

frontend/src/main.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ModalService } from "@maykin-ui/admin-ui";
12
import { StrictMode } from "react";
23
import { createRoot } from "react-dom/client";
34
import { RouterProvider, createBrowserRouter } from "react-router";
@@ -11,6 +12,8 @@ const root = document.getElementById("root") as HTMLElement;
1112

1213
createRoot(root).render(
1314
<StrictMode>
14-
<RouterProvider router={router} />
15+
<ModalService>
16+
<RouterProvider router={router} />
17+
</ModalService>
1518
</StrictMode>,
1619
);

0 commit comments

Comments
 (0)