UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

71 lines 3.86 kB
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, getUrlParamsWithBloatCheck } from "../../../logic/Links/UrlFunctions"; import { GeneralErrorLog, SecureCDNalyticsWebAbsolute } from "../interfaces/constants"; import { check4Gulp } from "../../../logic/Links/CheckGulping"; /** * 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 = getUrlParamsWithBloatCheck(); 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`; // https://github.com/fps-solutions/HubCon/issues/141 if (saveItem.zzzRichText1 && saveItem.zzzRichText1.indexOf(`${GeneralErrorLog} does not exist`) > -1) { if (check4Gulp() === true) console.log(`GEL ~ 95 - GeneralErrorLog was not found`); return; // https://github.com/fps-solutions/Entra-Spectives/issues/53 // https://github.com/fps-solutions/Item-Ninja/issues/72 } else if (postAPI.indexOf(`${GeneralErrorLog}`) > -1 && saveItem.zzzRichText1 && saveItem.zzzRichText1.indexOf(`Access is denied`) > -1) { if (check4Gulp() === true) console.log(`GEL ~ 81 - GeneralErrorLog Access is denied, can be if Elevated account expired in browser :)`); return; } 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