Notes/client/src/api/client.ts
Claudio Schaad 73ed2e2cf1 Scaffold Reading Notes app: React/Vite PWA client, Express server with Nextcloud Collectives integration
Notes are saved as markdown pages in a Nextcloud collective via the Collectives OCS API (page metadata/creation) and WebDAV (content read/append), following the same npm-workspaces + session-auth architecture as CityTracker.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NvmYFQSMqs2N3q2zUDNTVn
2026-08-26 20:07:40 +02:00

20 lines
489 B
TypeScript

export async function apiFetch<T>(path: string, init?: RequestInit): Promise<T> {
const res = await fetch(path, {
...init,
credentials: "include",
headers: {
"Content-Type": "application/json",
...init?.headers
}
});
if (!res.ok) {
const body = await res.json().catch(() => ({}));
throw new Error(body.error ?? `Request failed (${res.status})`);
}
if (res.status === 204) {
return undefined as T;
}
return (await res.json()) as T;
}