improvements in fetchLeadsFromKeystone.js

This commit is contained in:
Denise_Datinguinoo committed 2026-08-25 12:50:05 +02:00
1 parent 1b7cd4899e
commit 7a7dcfe3ad
2 files changed
+10 -5

No files matched your search

+9 -4
View File
@@ -18,12 +18,17 @@ async function getLeads(lastRunDate, currentDate, unsent, test) {
unsent: unsent, // If this variable is set to 0, then it will show leads that have been marked as seen (old leads)
test: test, // If this is removed or set to 0, then all leads that are returned would be marked as seen. This allows you to only fetch new leads
})
});
});
const result = await response.json();
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Keystone HTTP Error ${response.status} (${response.statusText}): ${ errorText }`);
}
if (!response.ok || !Array.isArray(result?.data)) {
console.log('API response empty or invalid: ', result.message || response.statusText);
const result = await response.json();
if (!Array.isArray(result?.data)) {
console.log('API response empty or invalid: ', result?.message || 'No data rray found');
return [];
}