Compare commits

..

2 Commits

Author SHA1 Message Date
josh 01d9703aec Merge pull request 'Improve API error messages: show HTTP status, catch network errors' (#6) from feature/auth-invites into main
CI / build-and-push (push) Successful in 37s
Reviewed-on: #6
2026-04-27 20:14:13 -04:00
josh 7348b35475 Improve API error messages: show HTTP status, catch network errors
"Unknown error" was hiding the actual HTTP status (likely 502 from
nginx). Now shows "HTTP 502 Bad Gateway" etc. Network TypeErrors
(connection refused) also get a clear message.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-27 20:03:34 -04:00
+5 -2
View File
@@ -86,8 +86,8 @@ async function request<T>(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<T>(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);