debug(api): log fetch lifecycle for all missions API calls
Adds [api] arrow logs on entry, resolve, and error paths so we can see in devtools console EXACTLY which endpoint hangs and for how long.
This commit is contained in:
@@ -181,13 +181,25 @@ async function api<T>(path: string, init?: RequestInit): Promise<T> {
|
|||||||
const method = init?.method ?? "GET";
|
const method = init?.method ?? "GET";
|
||||||
const busted =
|
const busted =
|
||||||
method === "GET" ? `${path}${path.includes("?") ? "&" : "?"}_t=${Date.now()}` : path;
|
method === "GET" ? `${path}${path.includes("?") ? "&" : "?"}_t=${Date.now()}` : path;
|
||||||
const r = await fetch(busted, {
|
const t0 = Date.now();
|
||||||
...init,
|
// eslint-disable-next-line no-console
|
||||||
headers: {
|
console.log(`[api] → ${method} ${busted}`);
|
||||||
"Content-Type": "application/json",
|
let r: Response;
|
||||||
...(init?.headers ?? {}),
|
try {
|
||||||
},
|
r = await fetch(busted, {
|
||||||
});
|
...init,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
...(init?.headers ?? {}),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(`[api] ✗ ${method} ${busted} (${Date.now() - t0}ms):`, e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(`[api] ← ${method} ${busted} (${Date.now() - t0}ms) status=${r.status}`);
|
||||||
if (!r.ok) {
|
if (!r.ok) {
|
||||||
const text = await r.text().catch(() => "");
|
const text = await r.text().catch(() => "");
|
||||||
throw new Error(`${init?.method ?? "GET"} ${path} → ${r.status} ${text}`);
|
throw new Error(`${init?.method ?? "GET"} ${path} → ${r.status} ${text}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user