Some checks failed
deploy / deploy (push) Failing after 39s
Proof: npm test passed 164/164; npm run operator-dashboard:build passed; focused dashboard API client and UI static tests cover timeout, empty HTTP 500, and retry/error loading state. Assumptions: The current stuck dashboard is caused by a stale or unavailable local kubectl port-forward; the app should fail visibly and allow retry instead of waiting forever. Still fake: no public dashboard ingress is part of this turn; local dashboard access still depends on Kubernetes API/port-forward availability.
30 lines
852 B
JavaScript
30 lines
852 B
JavaScript
export async function fetchJson(url, options = {}) {
|
|
const { timeoutMs = 15_000, ...fetchOptions } = options;
|
|
let timeout = null;
|
|
let controller = null;
|
|
|
|
if (!fetchOptions.signal && timeoutMs > 0) {
|
|
controller = new AbortController();
|
|
fetchOptions.signal = controller.signal;
|
|
timeout = globalThis.setTimeout(() => controller.abort(), timeoutMs);
|
|
}
|
|
|
|
try {
|
|
const response = await fetch(url, fetchOptions);
|
|
const text = await response.text();
|
|
const data = text ? JSON.parse(text) : null;
|
|
|
|
if (!response.ok) {
|
|
throw new Error(data?.error || `HTTP ${response.status}`);
|
|
}
|
|
|
|
return data;
|
|
} catch (error) {
|
|
if (controller?.signal.aborted) {
|
|
throw new Error(`Request timed out after ${timeoutMs}ms`);
|
|
}
|
|
throw error;
|
|
} finally {
|
|
if (timeout) globalThis.clearTimeout(timeout);
|
|
}
|
|
}
|