WIP and improved error handling

This commit is contained in:
Patrick Fic
2025-09-15 12:39:35 -07:00
parent de26979e44
commit c8771275ce
2 changed files with 189 additions and 350 deletions

View File

@@ -3,17 +3,29 @@ require("dotenv").config({
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
});
const GraphQLClient = require("graphql-request").GraphQLClient;
// const CalcualteAllocations = require("../cdk/cdk-calculate-allocations").default;
const InstanceMgr = require("../utils/instanceMgr").default;
const CreateFortellisLogEvent = require("./fortellis-logger");
const queries = require("../graphql-client/queries");
const logger = require("../utils/logger");
const uuid = require("uuid").v4;
const AxiosLib = require("axios").default;
const axios = AxiosLib.create();
const axiosCurlirize = require('axios-curlirize').default;
// Custom error class for Fortellis API errors
class FortellisApiError extends Error {
constructor(message, details) {
super(message);
this.name = 'FortellisApiError';
this.reqId = details.reqId;
this.url = details.url;
this.apiName = details.apiName;
this.errorData = details.errorData;
this.errorStatus = details.errorStatus;
this.errorStatusText = details.errorStatusText;
this.originalError = details.originalError;
}
}
axiosCurlirize(axios, (result, err) => {
const { command } = result;
console.log("*** ~ axiosCurlirize ~ command:", command);
@@ -206,6 +218,24 @@ async function MakeFortellisCall({
} catch (error) {
console.log(`ReqID: ${ReqId} Error`, error.response?.data);
//console.log(`ReqID: ${ReqId} Full Error`, JSON.stringify(error, null, 4));
const errorDetails = {
reqId: ReqId,
url: fullUrl,
apiName,
errorData: error.response?.data,
errorStatus: error.response?.status,
errorStatusText: error.response?.statusText,
originalError: error
};
// CreateFortellisLogEvent(socket, "ERROR", `Error in MakeFortellisCall for ${apiName}: ${error.message}`, {
// ...errorDetails,
// errorStack: error.stack
// });
// Throw custom error with all the details
throw new FortellisApiError(`Fortellis API call failed for ${apiName}: ${error.message}`, errorDetails);
}
}
@@ -332,6 +362,13 @@ const FortellisActions = {
type: "post",
apiName: "CDK Drive Post Accounts GL WIP",
},
ServiceHistoryInsert: {
url: isProduction
? "https://api.fortellis.io/cdk/drive/post/service-vehicle-history-mgmt/v2/"
: "https://api.fortellis.io/cdk-test/drive/post/service-vehicle-history-mgmt/v2/",
type: "post",
apiName: "CDK Drive Post Service Vehicle History",
},
};
@@ -349,7 +386,8 @@ const FortellisCacheEnums = {
selectedCustomerId: "selectedCustomerId",
DMSTransHeader: "DMSTransHeader",
transWips: "transWips",
DmsBatchTxnPost: "DmsBatchTxnPost"
DmsBatchTxnPost: "DmsBatchTxnPost",
DMSVehHistory: "DMSVehHistory",
};
function constructFullUrl({ url, pathParams = "", requestSearchParams = [] }) {
@@ -369,5 +407,6 @@ module.exports = {
MakeFortellisCall,
FortellisActions,
getTransactionType,
defaultFortellisTTL
defaultFortellisTTL,
FortellisApiError
};