Skip to content
Open

wip #75

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion schemas.gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -10328,4 +10328,4 @@
}
}
}
}
}
19 changes: 16 additions & 3 deletions utils/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,22 @@ export const fetchSafe = async (
) => {
const url = init?.withProxyCache ? await toProxyCache(input, init) : input;

const response = await retryExceptionOr500.execute(async () =>
await fetch(url, init)
);
const start = performance.now();
const response = await fetch(url, init);
const duration = performance.now() - start;

const isGet = !init?.method || init.method === "GET";
const isHit = response.headers.get("x-cache") === "HIT";
const servedBy = response.headers.get("x-served-by");
const age = response.headers.get("Age");

if (isGet) {
console.log(
`[${
duration.toFixed(0)
}ms]: hit: ${isHit}, servedBy: ${servedBy}, age: ${age}`,
);
}

if (response.ok) {
return response;
Expand Down