diff --git a/website/api/controllers/webhooks/receive-from-clay.js b/website/api/controllers/webhooks/receive-from-clay.js index e5e0fee44c..11e370c965 100644 --- a/website/api/controllers/webhooks/receive-from-clay.js +++ b/website/api/controllers/webhooks/receive-from-clay.js @@ -51,6 +51,9 @@ module.exports = { exits: { success: { description: 'Information about LinkedIn activity has successfully been received.' }, + duplicateContactOrAccountFound: {description: 'A contact or account could not be created because a duplicate record exists.', statusCode: 409 }, + couldNotCreateContactOrAccount: { description: 'A contact or account could not be created in the CRM using the provided information.' }, + couldNotCreateActivity: { description: 'An error occured when trying to create a historical event record in the CRM' }, }, @@ -73,10 +76,14 @@ module.exports = { contactSource, jobTitle, }).intercept((err)=>{ - return new Error(`When the receive-from-clay webhook received information about LinkedIn activity, a contact/account could not be created or updated. Full error: ${require('util').inspect(err)}`); + sails.log.warn(`When the receive-from-clay webhook received information about LinkedIn activity, a contact/account could not be created or updated. Full error: ${require('util').inspect(err)}`); + if(typeof err.errorCode !== 'undefined' && err.errorCode === 'DUPLICATES_DETECTED') { + return 'duplicateContactOrAccountFound'; + } else { + return 'couldNotCreateContactOrAccount'; + } }); - let trimmedLinkedinUrl = linkedinUrl.replace(sails.config.custom.RX_PROTOCOL_AND_COMMON_SUBDOMAINS, ''); // Create the new Fleet website page view record. @@ -101,7 +108,8 @@ module.exports = { Interactor_profile_url__c: trimmedLinkedinUrl,// eslint-disable-line camelcase }); }).intercept((err)=>{ - return new Error(`When the receive-from-clay webhook received information about linkedIn activity, a historical event record could not be created. Full error: ${require('util').inspect(err)}`); + sails.log.warn(`When the receive-from-clay webhook received information about LinkedIn activity, a historical event record could not be created. Full error: ${require('util').inspect(err)}`); + return 'couldNotCreateActivity'; }); // All done.