From 8db8744782c53753ad588f69c72cd05c95626cb2 Mon Sep 17 00:00:00 2001 From: Allan Carr Date: Fri, 27 Mar 2026 15:38:27 -0700 Subject: [PATCH] IO-3629 PostBatchWip Rtn != 0 error Signed-off-by: Allan Carr --- server/fortellis/fortellis.js | 52 +++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/server/fortellis/fortellis.js b/server/fortellis/fortellis.js index 02ed67852..ee01691e9 100644 --- a/server/fortellis/fortellis.js +++ b/server/fortellis/fortellis.js @@ -334,30 +334,48 @@ async function FortellisSelectedCustomer({ socket, redisHelpers, selectedCustome socket.emit("export-success", JobData.id); } else { //There was something wrong. Throw an error to trigger clean up. - //throw new Error("Error posting DMS Batch Transaction"); + const batchPostError = new Error(DmsBatchTxnPost.sendline || "Error posting DMS Batch Transaction"); + batchPostError.errorData = { DMSTransHeader, DmsBatchTxnPost }; + throw batchPostError; } - } catch { + } catch (error) { //Clean up the transaction and insert a faild error code // //Get the error code CreateFortellisLogEvent(socket, "DEBUG", `{6.1} Getting errors for Transaction ID ${DMSTransHeader.transID}`); - const DmsError = await QueryDmsErrWip({ socket, redisHelpers, JobData }); - // //Delete the transaction + let dmsErrors = []; + try { + const DmsError = await QueryDmsErrWip({ socket, redisHelpers, JobData }); + dmsErrors = Array.isArray(DmsError?.errMsg) ? DmsError.errMsg.filter((e) => e !== null && e !== "") : []; + + dmsErrors.forEach((e) => { + CreateFortellisLogEvent(socket, "ERROR", `Error encountered in posting transaction => ${e} `); + }); + } catch (queryError) { + CreateFortellisLogEvent( + socket, + "ERROR", + `{6.1} Unable to read ErrWIP for Transaction ID ${DMSTransHeader.transID}: ${queryError.message}` + ); + } + + //Delete the transaction, even if querying ErrWIP fails. CreateFortellisLogEvent(socket, "DEBUG", `{6.2} Deleting Transaction ID ${DMSTransHeader.transID}`); + try { + await DeleteDmsWip({ socket, redisHelpers, JobData }); + } catch (cleanupError) { + CreateFortellisLogEvent( + socket, + "ERROR", + `{6.2} Failed cleanup for Transaction ID ${DMSTransHeader.transID}: ${cleanupError.message}` + ); + } - await DeleteDmsWip({ socket, redisHelpers, JobData }); - - DmsError.errMsg.map( - (e) => - e !== null && - e !== "" && - CreateFortellisLogEvent(socket, "ERROR", `Error encountered in posting transaction => ${e} `) - ); - await InsertFailedExportLog({ - socket, - JobData, - error: DmsError.errMsg - }); + if (!error.errorData || typeof error.errorData !== "object") { + error.errorData = {}; + } + error.errorData.issues = dmsErrors.length ? dmsErrors : [error.message]; + throw error; } } } catch (error) {