Compare commits
2 Commits
8e5dca471e
...
01d9703aec
| Author | SHA1 | Date | |
|---|---|---|---|
| 01d9703aec | |||
| 7348b35475 |
@@ -86,8 +86,8 @@ async function request<T>(path: string, options: RequestInit & { timeoutMs?: num
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const body = await res.json().catch(() => ({ error: 'Unknown error' }));
|
const body = await res.json().catch(() => null);
|
||||||
throw new Error(body.error || `HTTP ${res.status}`);
|
throw new Error(body?.error || `HTTP ${res.status} ${res.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.json();
|
return res.json();
|
||||||
@@ -95,6 +95,9 @@ async function request<T>(path: string, options: RequestInit & { timeoutMs?: num
|
|||||||
if (e instanceof DOMException && e.name === 'AbortError') {
|
if (e instanceof DOMException && e.name === 'AbortError') {
|
||||||
throw new Error('Request timed out — server may be unreachable');
|
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;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
|
|||||||
Reference in New Issue
Block a user