path correction
This commit is contained in:
+9
-1
@@ -22,7 +22,15 @@ async function apiFetch(path, options = {}) {
|
||||
|
||||
const res = await fetch(`${API_BASE}${path}`, { ...options, headers });
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) throw new Error(data.error || 'Request failed');
|
||||
if (!res.ok) {
|
||||
const fallback =
|
||||
res.status === 404
|
||||
? 'API not found. Deploy server/ and run: npm run server (port 3001)'
|
||||
: res.status === 502
|
||||
? 'API server unreachable. Start Node on the host (port 3001).'
|
||||
: 'Request failed';
|
||||
throw new Error(data.error || fallback);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user