From 755ac7f657b74b159470bf6bac56c338042ccef3 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Wed, 13 Oct 2021 15:24:14 -0700 Subject: [PATCH] IO-256 Improved Logging --- server/accounting/qbo/qbo-payables.js | 19 +++++++++++++++---- server/accounting/qbo/qbo-payments.js | 11 +++++++++-- server/accounting/qbo/qbo-receivables.js | 9 ++++++++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/server/accounting/qbo/qbo-payables.js b/server/accounting/qbo/qbo-payables.js index 704ed50b4..a473ffab2 100644 --- a/server/accounting/qbo/qbo-payables.js +++ b/server/accounting/qbo/qbo-payables.js @@ -78,7 +78,9 @@ exports.default = async (req, res) => { ret.push({ billid: bill.id, success: false, - errorMessage: JSON.stringify(error), + errorMessage: + (error && error.authResponse && error.authResponse.body) || + JSON.stringify(error), }); } } @@ -113,7 +115,9 @@ async function QueryVendorRecord(oauthClient, req, bill) { ); } catch (error) { logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, { - error: JSON.stringify(error), + error: + (error && error.authResponse && error.authResponse.body) || + JSON.stringify(error), method: "QueryVendorRecord", }); throw error; @@ -136,7 +140,9 @@ async function InsertVendorRecord(oauthClient, req, bill) { return result && result.Vendor; } catch (error) { logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, { - error: JSON.stringify(error), + error: + (error && error.authResponse && error.authResponse.body) || + JSON.stringify(error), method: "InsertVendorRecord", }); throw error; @@ -169,6 +175,9 @@ async function InsertBill(oauthClient, req, bill, vendor) { ) ), }; + logger.log("qbo-payable-objectlog", "DEBUG", req.user.email, bill.id, { + billQbo, + }); try { const result = await oauthClient.makeApiCall({ url: urlBuilder( @@ -185,7 +194,9 @@ async function InsertBill(oauthClient, req, bill, vendor) { return result && result.Bill; } catch (error) { logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, { - error: JSON.stringify(error), + error: + (error && error.authResponse && error.authResponse.body) || + JSON.stringify(error), method: "InsertBill", }); throw error; diff --git a/server/accounting/qbo/qbo-payments.js b/server/accounting/qbo/qbo-payments.js index 012c3275f..149a4779f 100644 --- a/server/accounting/qbo/qbo-payments.js +++ b/server/accounting/qbo/qbo-payments.js @@ -128,13 +128,17 @@ exports.default = async (req, res) => { ret.push({ paymentid: payment.id, success: true }); } catch (error) { logger.log("qbo-payment-create-error", "ERROR", req.user.email, { - error: JSON.stringify(error), + error: + (error && error.authResponse && error.authResponse.body) || + JSON.stringify(error), }); ret.push({ paymentid: payment.id, success: false, - errorMessage: JSON.stringify(error), + errorMessage: + (error && error.authResponse && error.authResponse.body) || + JSON.stringify(error), }); } } @@ -187,6 +191,9 @@ async function InsertPayment(oauthClient, req, payment, parentRef) { }, ], }; + logger.log("qbo-payments-objectlog", "DEBUG", req.user.email, payment.id, { + paymentQbo, + }); try { const result = await oauthClient.makeApiCall({ url: urlBuilder(req.cookies.qbo_realmId, "payment"), diff --git a/server/accounting/qbo/qbo-receivables.js b/server/accounting/qbo/qbo-receivables.js index 29d0d5dc2..b0e3ea758 100644 --- a/server/accounting/qbo/qbo-receivables.js +++ b/server/accounting/qbo/qbo-receivables.js @@ -117,7 +117,9 @@ exports.default = async (req, res) => { ret.push({ jobid: job.id, success: false, - errorMessage: JSON.stringify(error), + errorMessage: + (error && error.authResponse && error.authResponse.body) || + JSON.stringify(error), }); } } @@ -397,10 +399,15 @@ async function InsertInvoice(oauthClient, req, job, bodyshop, parentTierRef) { : {}), }; + logger.log("qbo-receivable-objectlog", "DEBUG", req.user.email, job.id, { + invoiceObj, + }); + try { const result = await oauthClient.makeApiCall({ url: urlBuilder(req.cookies.qbo_realmId, "invoice"), method: "POST", + headers: { "Content-Type": "application/json", },