This commit is contained in:
chk
2026-06-14 13:41:02 +02:00
parent 8a669f23d3
commit 83cef32a37
5 changed files with 127 additions and 5 deletions

View File

@@ -79,15 +79,31 @@ async function _req(method, path, body) {
opts.headers = { 'content-type': 'application/json' };
opts.body = JSON.stringify(body);
}
const res = await fetch(url, opts);
console.log(`[FCode] → ${method} ${url}${body ? ' ' + JSON.stringify(body) : ''}`);
let res;
try {
res = await fetch(url, opts);
} catch (netErr) {
// Fileservice nicht erreichbar (DNS/Connection refused): klare Meldung statt "fetch failed".
console.error(`[FCode] ✖ ${method} ${url}: Fileservice nicht erreichbar (${netErr.message})`);
const e = new Error(`Fileservice nicht erreichbar: ${netErr.message}`);
e.code = 'FILESERVICE_UNREACHABLE';
throw e;
}
if (!res.ok) {
const err = await res.json().catch(() => ({}));
console.error(`[FCode] ✖ ${res.status} ${method} ${path}: ${err.code || ''} ${err.message || res.statusText}`);
const e = new Error(err.message || res.statusText);
e.code = err.code;
e.status = res.status;
throw e;
}
return res.json();
const data = await res.json();
console.log(`[FCode] ← ${res.status} ${method} ${path} ${JSON.stringify(data).slice(0, 160)}`);
return data;
}
module.exports = { isFCode, handle };