diff --git a/frontend/src/api/client.js b/frontend/src/api/client.js index 09a4e8d..d43e7a5 100644 --- a/frontend/src/api/client.js +++ b/frontend/src/api/client.js @@ -28,10 +28,21 @@ export function parseError(body, fallback) { export async function apiFetch(path, options = {}) { const token = options.token ?? getToken() - const res = await fetch(path, { - ...options, - headers: { ...apiHeaders(token), ...options.headers }, - }) + let res + try { + res = await fetch(path, { + ...options, + headers: { ...apiHeaders(token), ...options.headers }, + }) + } catch (err) { + const message = + err instanceof TypeError + ? 'Netzwerkfehler — Server nicht erreichbar. Bitte Verbindung prüfen oder Seite neu laden.' + : err.message || 'Netzwerkfehler bei der Anfrage' + const networkErr = new Error(message) + networkErr.cause = err + throw networkErr + } const body = await res.json().catch(() => null) if (!res.ok) { const message = parseError(body, `Anfrage fehlgeschlagen (${res.status})`) diff --git a/frontend/src/components/ProjectsSection.jsx b/frontend/src/components/ProjectsSection.jsx index d7c0c53..b28a7d9 100644 --- a/frontend/src/components/ProjectsSection.jsx +++ b/frontend/src/components/ProjectsSection.jsx @@ -109,13 +109,14 @@ export function ProjectsSection({ async function handleSubmit(e) { e.preventDefault() if (!title.trim()) return - await onCreate({ + const ok = await onCreate({ title: title.trim(), description: description.trim(), parent_project_id: parentProjectId || undefined, container_kind: containerKind || undefined, roadmap_item_id: gateId || undefined, }) + if (!ok) return setTitle('') setDescription('') setParentProjectId('') diff --git a/frontend/src/context/InitiativeOperationsContext.jsx b/frontend/src/context/InitiativeOperationsContext.jsx index f573517..e94fc27 100644 --- a/frontend/src/context/InitiativeOperationsContext.jsx +++ b/frontend/src/context/InitiativeOperationsContext.jsx @@ -430,11 +430,21 @@ export function InitiativeOperationsProvider({ children }) { async function handleCreateProject(body) { setFormBusy(true) + setError(null) try { await createInitiativeProject(id, body) - await load() + try { + setProjects(await listInitiativeProjects(id)) + } catch (refreshErr) { + setError( + `Projekt angelegt, aber die Liste konnte nicht aktualisiert werden: ${refreshErr.message}`, + ) + return false + } + return true } catch (err) { setError(err.message) + return false } finally { setFormBusy(false) }