mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-10-06 02:48:25 +00:00
Add URL context to API fetch errors for easier debugging
When the API server is unreachable, the raw "fetch failed" error gives no indication of what URL was being requested. Wrapping the error includes the target URL in the message while chaining the original cause. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3e28e6acda
commit
71f7af267a
1 changed files with 6 additions and 4 deletions
|
|
@ -58,10 +58,12 @@ export async function apiFetch(
|
|||
headers.set("Authorization", `Bearer ${token}`);
|
||||
}
|
||||
|
||||
return fetch(`${base_url}${path}`, {
|
||||
...init,
|
||||
headers,
|
||||
});
|
||||
const url = `${base_url}${path}`;
|
||||
try {
|
||||
return await fetch(url, { ...init, headers });
|
||||
} catch (cause) {
|
||||
throw new Error(`API request to ${url} failed`, { cause });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue