diff --git a/apps/web/src/lib/api-client.ts b/apps/web/src/lib/api-client.ts index 8c4d3f0..30fd16d 100644 --- a/apps/web/src/lib/api-client.ts +++ b/apps/web/src/lib/api-client.ts @@ -22,18 +22,24 @@ export class ApiError extends Error { async function fetchApi(path: string, options: RequestInit = {}): Promise { const url = `${API_BASE}${path.startsWith('/') ? path : `/${path}`}` + const headers = new Headers(options.headers) + if (options.body != null && !headers.has('Content-Type')) { + headers.set('Content-Type', 'application/json') + } const res = await fetch(url, { - headers: { 'Content-Type': 'application/json', ...options.headers }, ...options, + headers, }) if (!res.ok) { let message = res.statusText || 'API error' try { const data = (await res.json()) as { error?: string | { message?: string; code?: string } + message?: string } if (typeof data?.error === 'string') message = data.error else if (data?.error?.message) message = data.error.message + else if (typeof data?.message === 'string') message = data.message } catch { /* ignore */ }