Files
2026-10-29 11:57:29 +01:00

26 lines
1.1 KiB
JavaScript

// Generated, do not edit. sha256:2d07cc9fa8245d2a586ce4b51503f9ca7d40676b66802c6c06d44ad790d35373
import { CONFIG } from '../shared/config.js';
import { t } from './i18n/index.js';
import { serverFoutTekst } from './data/_rpc.js';
async function api(path, { method = 'GET', body = null } = {}) {
const ctl = new AbortController();
const timer = setTimeout(() => ctl.abort(), CONFIG.MARKET_SERVICE.CLIENT_TIMEOUT_MS);
try {
const res = await fetch(path, {
method,
signal: ctl.signal,
...(body ? { headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) } : {}),
});
const json = await res.json().catch(() => null);
if (!res.ok) throw new Error(serverFoutTekst(json) || `HTTP ${res.status}`);
return json;
} catch (e) {
if (e.name === 'AbortError') throw new Error(t('common.backendSilent', { s: CONFIG.MARKET_SERVICE.CLIENT_TIMEOUT_MS / 1000 }));
throw e;
} finally { clearTimeout(timer); }
}
export const status = () => api('/api/market/status');
export const test = () => api('/api/market/test', { method: 'POST', body: {} });