fix(sync): disable mock data fallback and handle null summary gracefully
This commit is contained in:
1 parent
8e22884464
commit
769d99b411
2 files changed
+10
-2
No files matched your search
@@ -18,6 +18,7 @@ function headersSite(useApiKey = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getMockDataForPath(path, params = {}) {
|
function getMockDataForPath(path, params = {}) {
|
||||||
|
return null;
|
||||||
if (path.includes('/data/stats/summary')) {
|
if (path.includes('/data/stats/summary')) {
|
||||||
return {
|
return {
|
||||||
download: 218648938113,
|
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_')) {
|
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);
|
return getMockDataForPath(path, params);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -373,6 +375,7 @@ async function netifyFetch(path, params = {}, useApiKey = false, agentUuid = nul
|
|||||||
const json = res.data;
|
const json = res.data;
|
||||||
if (json?.status_code !== 0) {
|
if (json?.status_code !== 0) {
|
||||||
console.error(`[Netify] API Error ${json?.status_code} pada ${path}: ${json?.status_message}`);
|
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 getMockDataForPath(path, params);
|
||||||
}
|
}
|
||||||
return json?.data ?? null;
|
return json?.data ?? null;
|
||||||
@@ -380,6 +383,7 @@ async function netifyFetch(path, params = {}, useApiKey = false, agentUuid = nul
|
|||||||
const s = err.response?.status;
|
const s = err.response?.status;
|
||||||
const msg = JSON.stringify(err.response?.data ?? err.message);
|
const msg = JSON.stringify(err.response?.data ?? err.message);
|
||||||
console.error(`[Netify] ${s ?? 'ERR'} ${path}: ${msg}. Falling back to mock data.`);
|
console.error(`[Netify] ${s ?? 'ERR'} ${path}: ${msg}. Falling back to mock data.`);
|
||||||
|
console.log('[DEBUG] FALLBACK due to catch error');
|
||||||
return getMockDataForPath(path, params);
|
return getMockDataForPath(path, params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,8 +160,12 @@ async function runPoll() {
|
|||||||
// 9. Bandwidth Timeline
|
// 9. Bandwidth Timeline
|
||||||
const summary = await netify.fetchBandwidthSummary(1440, agentUuid);
|
const summary = await netify.fetchBandwidthSummary(1440, agentUuid);
|
||||||
const devCount = devices?.length ?? 0;
|
const devCount = devices?.length ?? 0;
|
||||||
db.insertBandwidthTimeline({ ...summary, devices: devCount }, fetchedAt, SITE_UUID, agentUuid);
|
if (summary) {
|
||||||
console.log(`[Scheduler] OK Timeline : saved`);
|
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
|
// 21. TLS Versions
|
||||||
const tlsVer = await netify.fetchTLSVersions(1440, 10, agentUuid);
|
const tlsVer = await netify.fetchTLSVersions(1440, 10, agentUuid);
|
||||||
|
|||||||
Reference in new issue
Block a user