This function is being called by a parent function, that should return the success object, or the error.
I'm having trouble using async while trying to retry a function 4 times. On success it's all good. On error, I'm getting "Unhandled Promise Rejection".
//create record
const createSFDCRecord = async (object, userData) => {
console.log("trial", retryCount)
return await conn.sobject(object).create(userData, async (err, ret) => {
if (err || !ret.success) {
if (retryCount < retryLimit) {
setTimeout(async () => {
return await createSFDCRecord(object, userData)
}, 2000)
retryCount++
} else {
pagerDutyEvent(
`Failed to send ${userData.Trigger_Code_kcrm__c} form data into ${object} after 5x`,
"error",
err
)
}
}
console.log(`Created ${object} id : ${ret.id}`)
})
}
sobject is from jsforce http://jsforce.github.io/jsforce/doc/SObject.html
setTimeout