@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
57 lines • 3.02 kB
JavaScript
import { getThisFPSDigestValueFromUrl } from "../../../components/molecules/SpHttp/digestValues/fromUrl/getThisFPSDigestValueFromUrl";
import { doSpJsFetchOrPost } from "../../../components/molecules/SpHttp/Js/doSpJsFetch";
import { createMinHeaders } from "../../../components/molecules/SpHttp/helpers/headerInitUtilities";
import { getCurrentPageLink, getUrlVarsAsStrings } from "../../../logic/Links/UrlFunctions";
import { SecureCDNalyticsWebAbsolute } from "../interfaces/constants";
/**
* 2024-12-09: Migrated this function from it's original location here: \components\molecules\process-results\Logging.ts
*
* @param errorInfo
* @param errorInput
* @returns
*/
export async function saveErrorToLogWDigest(errorInfo, errorInput) {
//Return if you are not supposed to log an error
if (errorInput.logErrors !== true) {
return;
}
// https://github.com/mikezimm/fps-library-v2/issues/15
if (!errorInfo) {
return;
}
const { traceString, alertMe, consoleLog, } = errorInput;
let trace = traceString ? traceString.split('|') : [];
let getParams = JSON.stringify(getUrlVarsAsStrings());
let parsedMessage = errorInfo.returnMess.split('-- FULL ERROR MESSAGE:');
let zzzRichText1 = parsedMessage.length > 0 ? parsedMessage[0] : 'No friendly error';
let zzzRichText2 = parsedMessage.length > 0 ? parsedMessage[1] : errorInfo.returnMess;
let saveItem = {
// https://github.com/fps-solutions/HubCon/issues/103
__metadata: { type: `` },
Title: trace[0],
Result: trace[3] ? trace[3] : null,
zzzText1: trace[4] ? trace[4] : null,
zzzText2: trace[5] ? trace[5] : null,
zzzText3: trace[6] ? trace[6] : null,
zzzText6: typeof alertMe === 'string' ? alertMe : `${alertMe}`,
zzzText7: typeof consoleLog === 'string' ? consoleLog : `${consoleLog}`,
zzzNumber1: trace[7] ? trace[7] : null,
zzzNumber2: trace[8] ? trace[8] : null,
getParams: getParams,
PageLink: getCurrentPageLink(),
zzzRichText1: zzzRichText1,
zzzRichText2: zzzRichText2,
};
let absoluteWebUrl = trace[1] ? trace[1] : `${SecureCDNalyticsWebAbsolute}`;
let list = trace[2] ? trace[2] : 'GeneralErrorLog';
// https://github.com/fps-solutions/HubCon/issues/103
// Required for non-PnpJS POST operations
saveItem.__metadata = { type: `SP.Data.${list}ListItem` };
// https://github.com/fps-solutions/HubCon/issues/103
const formDigestValue = await getThisFPSDigestValueFromUrl(absoluteWebUrl);
let postAPI = `${absoluteWebUrl}/_api/web/lists/getbytitle('${list}')/items`;
doSpJsFetchOrPost(postAPI, 'POST', createMinHeaders(postAPI, formDigestValue, ''), saveItem);
// const TEMPAlert = `saveErrorToLog Alert:\n\nerrorInfo\n${JSON.stringify(errorInfo)}\n\nerrorInput:\n\nerrorInput\n${errorInput}`
// alert(TEMPAlert);
}
//# sourceMappingURL=saveErrorToLogWDigest.js.map