Skip to content

Commit

Permalink
update: logging updates
Browse files Browse the repository at this point in the history
  • Loading branch information
DaKingKong committed Sep 13, 2024
1 parent 605743f commit 3742d1f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 36 deletions.
21 changes: 0 additions & 21 deletions src/adapters/netsuite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ async function getUserInfo({ authHeader, additionalInfo, query }) {
}
};
} catch (error) {
console.log({ message: "Error in getting User Info", error });
const isForbiddenError = isNetSuiteForbiddenError(error);
const errorMessage = isForbiddenError
? "Permission violation: Make Sure You have 'Lists -> Employee Record & Lists -> Employee' permission to authorize. Please contact your administrator."
Expand All @@ -71,7 +70,6 @@ async function getUserInfo({ authHeader, additionalInfo, query }) {
}

async function unAuthorize({ user }) {
console.log({ message: "Intiating to unauthorize user", userId: user.id });
const revokeUrl = `https://${user.hostname.split(".")[0]}.suitetalk.api.netsuite.com/services/rest/auth/oauth2/v1/revoke`;
const basicAuthHeader = Buffer.from(`${process.env.NETSUITE_CRM_CLIENT_ID}:${process.env.NETSUITE_CRM_CLIENT_SECRET}`).toString('base64');
const refreshTokenParams = new url.URLSearchParams({
Expand All @@ -83,7 +81,6 @@ async function unAuthorize({ user }) {
{
headers: { 'Authorization': `Basic ${basicAuthHeader}` }
});
console.log(`Access and Refresh Token is revoked for user ${user.id}...`);
await user.destroy();
return {
returnMessage: {
Expand Down Expand Up @@ -116,7 +113,6 @@ async function findContact({ user, authHeader, phoneNumber, overridingFormat })
}
const matchedContactInfo = [];
for (var numberToQuery of numberToQueryArray) {
console.log({ message: "Finding Contact with the number", numberToQuery });
if (numberToQuery !== 'undefined' && numberToQuery !== null && numberToQuery !== '') {
//For Contact search
const personInfo = await axios.post(
Expand All @@ -127,7 +123,6 @@ async function findContact({ user, authHeader, phoneNumber, overridingFormat })
{
headers: { 'Authorization': authHeader, 'Content-Type': 'application/json', 'Prefer': 'transient' }
});
console.log(personInfo);
if (personInfo.data.items.length > 0) {
for (var result of personInfo.data.items) {
let firstName = result.firstname ?? '';
Expand All @@ -152,7 +147,6 @@ async function findContact({ user, authHeader, phoneNumber, overridingFormat })
{
headers: { 'Authorization': authHeader, 'Content-Type': 'application/json', 'Prefer': 'transient' }
});
console.log({ message: "Custome Search", customerInfo });
if (customerInfo.data.items.length > 0) {
for (var result of customerInfo.data.items) {
let firstName = result.firstname ?? '';
Expand Down Expand Up @@ -180,7 +174,6 @@ async function findContact({ user, authHeader, phoneNumber, overridingFormat })
matchedContactInfo,
};
} catch (error) {
console.log({ message: "Error in Finding Contact/Customer", error });
const isForbiddenError = isNetSuiteForbiddenError(error);
const errorMessage = isForbiddenError
? "Permission violation: Make Sure You have 'Reports -> SuiteAnalytics Workbook, Lists -> Contacts & Lists -> Customer' permission to fetch details. Please contact your administrator."
Expand Down Expand Up @@ -252,15 +245,13 @@ async function createCallLog({ user, contactInfo, authHeader, callLog, note, add
if (phoneCallResponse.data.items.length > 0) {
callLogId = phoneCallResponse.data.items[0].id;
}
console.log(`call log id... \n${callLogId}`);
await axios.patch(`https://${user.hostname.split(".")[0]}.suitetalk.api.netsuite.com/services/rest/record/v1/phoneCall/${callLogId}`,
{
message: originalMessage
},
{
headers: { 'Authorization': authHeader }
});*/
console.log({ message: "Call Log Added with CallLogId", callLogId });
return {
logId: callLogId,
returnMessage: {
Expand All @@ -270,7 +261,6 @@ async function createCallLog({ user, contactInfo, authHeader, callLog, note, add
}
};
} catch (error) {
console.log({ message: "Error in creating Call Log", error });
const isForbiddenError = isNetSuiteForbiddenError(error);
const errorMessage = isForbiddenError
? "Permission violation: Make Sure You have 'Lists -> Phone Calls, Lists -> Contacts & Lists -> Customers' permission to CallLog. Please contact your administrator."
Expand All @@ -288,7 +278,6 @@ async function createCallLog({ user, contactInfo, authHeader, callLog, note, add
}

async function getCallLog({ user, callLogId, authHeader }) {
console.log({ message: "Finding Call With Id", callLogId });
try {
const getLogRes = await axios.get(`https://${user.hostname.split(".")[0]}.suitetalk.api.netsuite.com/services/rest/record/v1/phonecall/${callLogId}`,
{
Expand All @@ -307,7 +296,6 @@ async function getCallLog({ user, callLogId, authHeader }) {
}
}
} catch (error) {
console.log({ message: "Error in getting Call Log", error });
const isForbiddenError = isNetSuiteForbiddenError(error);
const errorMessage = isForbiddenError
? "Permission violation: Make Sure You have 'Lists -> Phone Calls, Lists -> Contacts & Lists -> Customers' permission to CallLog. Please contact your administrator."
Expand Down Expand Up @@ -345,7 +333,6 @@ async function updateCallLog({ user, existingCallLog, authHeader, recordingLink,
}
else {
originalNote = messageBody.split('\n\n--- Created via RingCentral CRM Extension')[0].split('Note: ')[1];
console.log({ originalNote });
}

messageBody = messageBody.replace(`Note: ${originalNote}`, `Note: ${note}`);
Expand All @@ -366,7 +353,6 @@ async function updateCallLog({ user, existingCallLog, authHeader, recordingLink,
}
};
} catch (error) {
console.log({ message: "Error in Updating Call Log", error });
const isForbiddenError = isNetSuiteForbiddenError(error);
const errorMessage = isForbiddenError
? "Permission violation: Make Sure You have 'Lists -> Phone Calls, Lists -> Contacts & Lists -> Customers' permission to CallLog. Please contact your administrator."
Expand Down Expand Up @@ -450,7 +436,6 @@ async function createMessageLog({ user, contactInfo, authHeader, message, additi
headers: { 'Authorization': authHeader }
});
const callLogId = extractIdFromUrl(addLogRes.headers.location);
console.log({ message: "CallLogId is", callLogId });
return {
logId: callLogId,
returnMessage: {
Expand All @@ -460,7 +445,6 @@ async function createMessageLog({ user, contactInfo, authHeader, message, additi
}
};
} catch (error) {
console.log({ message: "Error in creating Message Log", error });
const isForbiddenError = isNetSuiteForbiddenError(error);
const errorMessage = isForbiddenError
? "Permission violation: Make Sure You have 'Lists -> Phone Calls, Lists -> Contacts & Lists -> Customers' permission to Message Log. Please contact your administrator."
Expand Down Expand Up @@ -511,7 +495,6 @@ async function updateMessageLog({ user, contactInfo, existingMessageLog, message
}
};
} catch (error) {
console.log({ message: "Error in Updating Message Log", error });
const isForbiddenError = isNetSuiteForbiddenError(error);
const errorMessage = isForbiddenError
? "Permission violation: Make Sure You have 'Lists -> Phone Calls, Lists -> Contacts & Lists -> Customers' permission to MessageLog. Please contact your administrator."
Expand Down Expand Up @@ -577,7 +560,6 @@ async function createContact({ user, authHeader, phoneNumber, newContactName, ne
contactId = extractIdFromUrl(createContactRes.headers.location);
break;
} catch (error) {
console.log({ message: "Error in creating Contact", error });
return {
contactInfo: {
id: contactId,
Expand Down Expand Up @@ -611,7 +593,6 @@ async function createContact({ user, authHeader, phoneNumber, newContactName, ne
contactId = extractIdFromUrl(createCustomerRes.headers.location);
break;
} catch (error) {
console.log({ message: "Error in creating Customer", error });
return {
contactInfo: {
id: contactId,
Expand Down Expand Up @@ -641,7 +622,6 @@ async function createContact({ user, authHeader, phoneNumber, newContactName, ne
}
}
} catch (error) {
console.log({ message: "Error in creating Contact/Customer", error });
const isForbiddenError = isNetSuiteForbiddenError(error);
const errorMessage = isForbiddenError
? "Permission violation: Make Sure You have 'Lists -> Contacts & Lists -> Customers' permission to Create Contact/Customer. Please contact your administrator."
Expand Down Expand Up @@ -691,7 +671,6 @@ function isNetSuiteForbiddenError(error) {
}
return false;
} catch (error) {
console.log({ message: "Error in parsing NetSuite Error", error });
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function findContact({ platform, userId, phoneNumber, overridingFormat })
return { successful: false, returnMessage };
}
} catch (e) {
console.log(`Error: status: ${e.response?.status}. message: ${e.response?.message}. platform: ${platform}`);
console.log(`platform: ${platformName} \n${e.stack}`);
if (e.response?.status === 429) {
return { successful: false, returnMessage: { message: `${platform} rate limit reached. Please try again the next minute.`, messageType: 'warning', ttl: 5000 } };
}
Expand Down Expand Up @@ -82,7 +82,7 @@ async function createContact({ platform, userId, phoneNumber, newContactName, ne
return { successful: false, returnMessage };
}
} catch (e) {
console.log(`Error: status: ${e.response?.status}. message: ${e.response?.message}. platform: ${platform}`);
console.log(`platform: ${platformName} \n${e.stack}`);
if (e.response?.status === 429) {
return { successful: false, returnMessage: { message: `${platform} rate limit reached. Please try again the next minute.`, messageType: 'warning', ttl: 5000 } };
}
Expand Down
26 changes: 13 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ app.get('/pipedrive-redirect', function (req, res) {
res.sendFile(path.join(__dirname, 'adapters/pipedrive/redirect.html'));
}
catch (e) {
console.log(`Error: status: ${e.response?.status}. message: ${e.response?.message}.`);
console.log(`platform: ${platformName} \n${e.stack}`);
res.status(500).send(e);
}
})
Expand All @@ -105,7 +105,7 @@ app.delete('/pipedrive-redirect', async function (req, res) {
}
}
catch (e) {
console.log(`Error: status: ${e.response?.status}. message: ${e.response?.message}`);
console.log(`platform: ${platformName} \n${e.stack}`);
res.status(500).send(e);
}
})
Expand All @@ -130,7 +130,7 @@ app.get('/hostname', async function (req, res) {
}
}
catch (e) {
console.log(`Error: status: ${e.response?.status}. message: ${e.response?.message}`);
console.log(`platform: ${platformName} \n${e.stack}`);
res.status(500).send(e);
}
})
Expand Down Expand Up @@ -178,7 +178,7 @@ app.get('/oauth-callback', async function (req, res) {
}
}
catch (e) {
console.log(`Error: status: ${e.response?.status}. message: ${e.response?.message}. platform: ${platformName}`);
console.log(`platform: ${platformName} \n${e.stack}`);
res.status(400).send(e);
success = false;
}
Expand Down Expand Up @@ -222,7 +222,7 @@ app.post('/apiKeyLogin', async function (req, res) {
success = true;
}
catch (e) {
console.log(`Error: status: ${e.response?.status}. message: ${e.response?.message}. platform: ${platformName}`);
console.log(`platform: ${platformName} \n${e.stack}`);
res.status(400).send(e);
success = false;
}
Expand Down Expand Up @@ -271,7 +271,7 @@ app.post('/unAuthorize', async function (req, res) {
}
}
catch (e) {
console.log(`Error: status: ${e.response?.status}. message: ${e.response?.message}. platform: ${platformName}`);
console.log(`platform: ${platformName} \n${e.stack}`);
res.status(400).send(e);
success = false;
}
Expand All @@ -296,7 +296,7 @@ app.get('/userInfoHash', async function (req, res) {
res.status(200).send({ extensionId, accountId });
}
catch (e) {
console.log(`Error: status: ${e.response?.status}. message: ${e.response?.message}`);
console.log(`platform: ${platformName} \n${e.stack}`);
res.status(400).send(e);
}
})
Expand Down Expand Up @@ -326,7 +326,7 @@ app.get('/contact', async function (req, res) {
}
}
catch (e) {
console.log(`Error: status: ${e.response?.status}. message: ${e.response?.message}. platform: ${platformName}`);
console.log(`platform: ${platformName} \n${e.stack}`);
res.status(400).send(e);
success = false;
}
Expand Down Expand Up @@ -367,7 +367,7 @@ app.post('/contact', async function (req, res) {
}
}
catch (e) {
console.log(`Error: status: ${e.response?.status}. message: ${e.response?.message}. platform: ${platformName}`);
console.log(`platform: ${platformName} \n${e.stack}`);
res.status(400).send(e);
success = false;
}
Expand Down Expand Up @@ -405,7 +405,7 @@ app.get('/callLog', async function (req, res) {
}
}
catch (e) {
console.log(`Error: status: ${e.response?.status}. message: ${e.response?.message}. platform: ${platformName}`);
console.log(`platform: ${platformName} \n${e.stack}`);
res.status(400).send(e);
success = false;
}
Expand Down Expand Up @@ -442,7 +442,7 @@ app.post('/callLog', async function (req, res) {
}
}
catch (e) {
console.log(`Error: status: ${e.response?.status}. message: ${e.response?.message}. platform: ${platformName}`);
console.log(`platform: ${platformName} \n${e.stack}`);
res.status(400).send(e);
success = false;
}
Expand Down Expand Up @@ -480,7 +480,7 @@ app.patch('/callLog', async function (req, res) {
}
}
catch (e) {
console.log(`Error: status: ${e.response?.status}. message: ${e.response?.message}. platform: ${platformName}`);
console.log(`platform: ${platformName} \n${e.stack}`);
res.status(400).send(e);
success = false;
}
Expand Down Expand Up @@ -518,7 +518,7 @@ app.post('/messageLog', async function (req, res) {
}
}
catch (e) {
console.log(`Error: status: ${e.response?.status}. message: ${e.response?.message}. platform: ${platformName}`);
console.log(`platform: ${platformName} \n${e.stack}`);
res.status(400).send(e);
success = false;
}
Expand Down

0 comments on commit 3742d1f

Please sign in to comment.