Files
ps5upload/client/src/lib/startRequestTimeout.ts
T
phantomptrandClaude Opus 5.5 69d2d4280d Link download and PS5 to PS5 start: give the start request a 60 s limit
Both started their engine job with a bare fetch, so an engine that never
answered left the button spinning forever. The start request now times
out after 60 s with an error that says what was being started.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ub1mez9eaVtTF8pMEFXvA9
2026-10-10 12:50:48 -07:00

29 lines
1.2 KiB
TypeScript

/** How long a request that only STARTS an engine job may take. Starting is quick (the work
* runs as a job afterwards); a request with no answer by then means the engine is stuck or
* gone, and without a limit the button would spin forever. */
export const START_TIMEOUT_MS = 60_000;
/** fetch with START_TIMEOUT_MS, turning the timeout into an error that says what happened. */
export async function fetchStart(
what: string,
input: string,
init: RequestInit,
fetchImpl: (input: string, init?: RequestInit) => Promise<Response> = (i, o) => fetch(i, o),
ms: number = START_TIMEOUT_MS,
): Promise<Response> {
try {
return await fetchImpl(input, { ...init, signal: AbortSignal.timeout(ms) });
} catch (e) {
const name = e instanceof Error || e instanceof DOMException ? e.name : "";
if (name === "TimeoutError" || name === "AbortError") {
const wrapped = new Error(
`The engine did not answer within ${Math.round(ms / 1000)} seconds while starting ${what}. Check that it is still running, then try again.`,
);
// The target is ES2020 (no Error options); keep the original for whoever inspects it.
(wrapped as Error & { cause?: unknown }).cause = e;
throw wrapped;
}
throw e;
}
}