unrip/src/operator-dashboard/static/lib/api.js
philipp 95a8e239fd
Some checks failed
deploy / deploy (push) Failing after 39s
Fail dashboard bootstrap visibly
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.
2026-05-12 22:18:37 +02:00

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);
}
}