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:
Bryan Helmkamp 2026-03-03 21:41:35 -05:00
parent 3e28e6acda
commit 71f7af267a

View file

@ -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 });
}
}
/**