UNPKG

@mikezimm/fps-core-v7

Version:

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

95 lines 5.02 kB
import { doSpHttpFetchOrPostAndCheck } from "../../../components/molecules/SpHttp/Sp/doSpHttpFetch"; 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 * * import { saveErrorToLog } from "@mikezimm/fps-core-v7/lib/restAPIs/logging/Analytics/saveErrorToLog"; * * @param errorInfo * @param errorInput * @returns */ export async function saveErrorToLog(errorInfo, errorInput, fpsSpService) { //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; } // https://github.com/mikezimm/fps-library-v2/issues/15 if (!fpsSpService) { console.log(`unable to saveErrorToLog due to no fpsSpService`); 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 PageLink = saveItem.PageLink; if (PageLink) { if (PageLink.Description.length > 254) { saveItem.Title += ` | PageLink.Desc to long, see zzzText4`; // https://github.com/mikezimm/pivottiles7/issues/488 saveItem.zzzText4 = `${PageLink.Description.split('?')[1]}`.substring(0, 245); PageLink.Description = PageLink.Description.split('?')[0]; } if (PageLink.Url.length > 254) { const extraText = ` | PageLink.Url to long, see zzzText4`; saveItem.Title += extraText; // https://github.com/mikezimm/pivottiles7/issues/488 saveItem.zzzText4 = `${PageLink.Url.split('?')[1]}`.substring(0, 245); PageLink.Url = `${PageLink.Url.split('?')[0]}/SEE_zzzText4_For_Url_Parameters`; PageLink.Description += extraText; } } let absoluteWebUrl = trace[1] ? trace[1] : `${SecureCDNalyticsWebAbsolute}`; let list = trace[2] ? trace[2] : `${GeneralErrorLog}`; if (list === GeneralErrorLog && zzzRichText1) // 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: string = 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; } // 2024-12-21: Not sure if this will work passing in '' for headerContentType doSpHttpFetchOrPostAndCheck(postAPI, 'POST', fpsSpService, 'application/json;odata=nometadata', false, true, 'item', false, saveItem); // const TEMPAlert = `saveErrorToLog Alert:\n\nerrorInfo\n${JSON.stringify(errorInfo)}\n\nerrorInput:\n\nerrorInput\n${errorInput}` // alert(TEMPAlert); } //# sourceMappingURL=saveErrorToLog.js.map