Users/chskelt/debug logging2 (#2503)

* Adding further console logging but also fixed lines with JSON.stringify(error)

* Added retry mechanism for GETs for armRequest workflow

* Moved stringifyError into its own file as it was causing strict compile issues in ErrorHandlingUtils
This commit is contained in:
vchske
2026-05-28 10:44:51 -07:00
committed by GitHub
parent 481e5cde3e
commit 8ab7d354e6
14 changed files with 498 additions and 39 deletions
+26 -4
View File
@@ -3,6 +3,11 @@
*
* Usage: await fetchWithTimeout(url, { method: 'GET', headers: {...} }, 10000);
*
* If `init.signal` is provided, it is combined with the internal timeout: aborting
* the caller's signal aborts the fetch (propagating the caller's abort reason), and
* the timeout still applies. Pass `timeoutMs: Infinity` to disable the timeout entirely
* (useful for long-running operations that should rely solely on caller cancellation).
*
* A shared helper to remove duplicated inline implementations across the codebase.
*/
export async function fetchWithTimeout(
@@ -10,13 +15,30 @@ export async function fetchWithTimeout(
init: RequestInit = {},
timeoutMs: number = 5000,
): Promise<Response> {
const externalSignal = init.signal;
if (externalSignal?.aborted) {
throw externalSignal.reason ?? new DOMException("The operation was aborted.", "AbortError");
}
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeoutMs);
const hasTimeout = Number.isFinite(timeoutMs);
const timeoutId = hasTimeout ? setTimeout(() => controller.abort(), timeoutMs) : undefined;
let onExternalAbort: (() => void) | undefined;
if (externalSignal) {
onExternalAbort = () => controller.abort(externalSignal.reason);
externalSignal.addEventListener("abort", onExternalAbort, { once: true });
}
try {
const response = await fetch(url, { ...init, signal: controller.signal });
return response;
return await fetch(url, { ...init, signal: controller.signal });
} finally {
clearTimeout(id);
if (timeoutId !== undefined) {
clearTimeout(timeoutId);
}
if (externalSignal && onExternalAbort) {
externalSignal.removeEventListener("abort", onExternalAbort);
}
}
}