feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Enhance logging
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const { RRClient } = require("./lib/index.cjs");
|
||||
const { getRRConfigFromBodyshop } = require("./rr-config");
|
||||
const RRLogger = require("./rr-logger");
|
||||
const CreateRRLogEvent = require("./rr-logger-event");
|
||||
const InstanceManager = require("../utils/instanceMgr").default;
|
||||
|
||||
/**
|
||||
@@ -206,30 +206,35 @@ const buildCustomerPayloadFromJob = (job, overrides = {}) => {
|
||||
* Maps data.dmsRecKey -> customerNo for compatibility with existing callers.
|
||||
*/
|
||||
const createRRCustomer = async ({ bodyshop, job, overrides = {}, socket }) => {
|
||||
const log = RRLogger(socket, { ns: "rr" });
|
||||
const { client, opts } = buildClientAndOpts(bodyshop);
|
||||
const payload = buildCustomerPayloadFromJob(job, overrides);
|
||||
|
||||
let res;
|
||||
let response;
|
||||
try {
|
||||
const safePayload = sanitizeRRCustomerPayload(payload);
|
||||
res = await client.insertCustomer(safePayload, opts);
|
||||
response = await client.insertCustomer(safePayload, opts);
|
||||
CreateRRLogEvent(socket, "SILLY", "RR createRRCustomer called", { response });
|
||||
} catch (e) {
|
||||
log("error", "RR insertCustomer transport error", { message: e?.message, stack: e?.stack, payload });
|
||||
CreateRRLogEvent(socket, "ERROR", "RR insertCustomer transport error", {
|
||||
message: e?.message,
|
||||
stack: e?.stack,
|
||||
payload
|
||||
});
|
||||
throw e;
|
||||
}
|
||||
|
||||
const data = res?.data ?? res;
|
||||
const trx = res?.statusBlocks?.transaction;
|
||||
const data = response?.data ?? response;
|
||||
const trx = response?.statusBlocks?.transaction;
|
||||
|
||||
let customerNo = data?.dmsRecKey;
|
||||
if (!customerNo) {
|
||||
log("error", "RR insertCustomer returned no dmsRecKey/custNo", {
|
||||
CreateRRLogEvent(socket, "ERROR", "RR insertCustomer returned no dmsRecKey/custNo", {
|
||||
status: trx?.status,
|
||||
statusCode: trx?.statusCode,
|
||||
message: trx?.message,
|
||||
data
|
||||
});
|
||||
|
||||
throw new Error(
|
||||
`RR insertCustomer returned no dmsRecKey (status=${trx?.status ?? "?"} code=${trx?.statusCode ?? "?"}${
|
||||
trx?.message ? ` msg=${trx.message}` : ""
|
||||
|
||||
Reference in New Issue
Block a user