diff --git a/src/fetchLeadsFromKeystone.js b/src/fetchLeadsFromKeystone.js index eba2341..c103334 100644 --- a/src/fetchLeadsFromKeystone.js +++ b/src/fetchLeadsFromKeystone.js @@ -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 []; } diff --git a/src/hubspotConnector.js b/src/hubspotConnector.js index 3c09312..985e31b 100644 --- a/src/hubspotConnector.js +++ b/src/hubspotConnector.js @@ -104,7 +104,7 @@ async function createHubspotContacts(leadContactsPayload) { for (let i = 0; i < leadContactsPayload.length; i += 100) { let payloadsBatch = leadContactsPayload.slice(i, i + 100); let payloadTest = [leadContactsPayload[0]]; - const creationContacts = await hubspot.upsertBatchCRMRecord('contacts', payloadsBatch); + const creationContacts = await hubspot.upsertBatchCRMRecord('contacts', payloadTest); if (creationContacts) { console.log('Batch successfully created!'); console.log(JSON.stringify(creationContacts, null, 2));