fix(sync): disable mock data fallback and handle null summary gracefully

This commit is contained in:
Rafif-Riqullah-Siregar committed 2026-07-06 09:28:44 +07:00
1 parent 8e22884464
commit 769d99b411
2 files changed
+10 -2

No files matched your search

+4
View File
@@ -18,6 +18,7 @@ function headersSite(useApiKey = false) {
}
function getMockDataForPath(path, params = {}) {
return null;
if (path.includes('/data/stats/summary')) {
return {
download: 218648938113,
@@ -364,6 +365,7 @@ async function netifyFetch(path, params = {}, useApiKey = false, agentUuid = nul
}
}
if (!JWT_TOKEN || !SITE_UUID || JWT_TOKEN === 'YOUR_JWT_TOKEN' || SITE_UUID === 'YOUR_SITE_UUID' || JWT_TOKEN.startsWith('change_me') || JWT_TOKEN.startsWith('YOUR_')) {
console.log('[DEBUG] FALLBACK due to invalid config', {hasToken: !!JWT_TOKEN, SITE_UUID});
return getMockDataForPath(path, params);
}
try {
@@ -373,6 +375,7 @@ async function netifyFetch(path, params = {}, useApiKey = false, agentUuid = nul
const json = res.data;
if (json?.status_code !== 0) {
console.error(`[Netify] API Error ${json?.status_code} pada ${path}: ${json?.status_message}`);
console.log('[DEBUG] FALLBACK due to API error', json);
return getMockDataForPath(path, params);
}
return json?.data ?? null;
@@ -380,6 +383,7 @@ async function netifyFetch(path, params = {}, useApiKey = false, agentUuid = nul
const s = err.response?.status;
const msg = JSON.stringify(err.response?.data ?? err.message);
console.error(`[Netify] ${s ?? 'ERR'} ${path}: ${msg}. Falling back to mock data.`);
console.log('[DEBUG] FALLBACK due to catch error');
return getMockDataForPath(path, params);
}
}
+6 -2
View File
@@ -160,8 +160,12 @@ async function runPoll() {
// 9. Bandwidth Timeline
const summary = await netify.fetchBandwidthSummary(1440, agentUuid);
const devCount = devices?.length ?? 0;
db.insertBandwidthTimeline({ ...summary, devices: devCount }, fetchedAt, SITE_UUID, agentUuid);
console.log(`[Scheduler] OK Timeline : saved`);
if (summary) {
db.insertBandwidthTimeline({ ...summary, devices: devCount }, fetchedAt, SITE_UUID, agentUuid);
console.log(`[Scheduler] OK Timeline : saved`);
} else {
console.log(`[Scheduler] -- Timeline : gagal ambil data`);
}
// 21. TLS Versions
const tlsVer = await netify.fetchTLSVersions(1440, 10, agentUuid);