Logging
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user