diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts index d1c7bdb..f3911b5 100644 --- a/apps/web/src/lib/api.ts +++ b/apps/web/src/lib/api.ts @@ -86,8 +86,8 @@ async function request(path: string, options: RequestInit & { timeoutMs?: num }); if (!res.ok) { - const body = await res.json().catch(() => ({ error: 'Unknown error' })); - throw new Error(body.error || `HTTP ${res.status}`); + const body = await res.json().catch(() => null); + throw new Error(body?.error || `HTTP ${res.status} ${res.statusText}`); } return res.json(); @@ -95,6 +95,9 @@ async function request(path: string, options: RequestInit & { timeoutMs?: num if (e instanceof DOMException && e.name === 'AbortError') { throw new Error('Request timed out — server may be unreachable'); } + if (e instanceof TypeError) { + throw new Error('Network error — server may be unreachable'); + } throw e; } finally { clearTimeout(timeout);