From 9d39c13510974b5ada2a6f6c2448da3f1b755a5c Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Fri, 10 Apr 2026 13:58:30 -0500 Subject: [PATCH] refactor(puchase): changes how the error handling works so a better email can be sent --- backend/purchase/puchase.gpCheck.ts | 22 +++++++++++++++------- backend/purchase/purchase.controller.ts | 14 ++++++++------ backend/utils/returnHelper.utils.ts | 3 ++- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/backend/purchase/puchase.gpCheck.ts b/backend/purchase/puchase.gpCheck.ts index e01559a..b1633c7 100644 --- a/backend/purchase/puchase.gpCheck.ts +++ b/backend/purchase/puchase.gpCheck.ts @@ -20,8 +20,8 @@ export const gpReqCheck = async (data: GpStatus[]) => { module: "purchase", subModule: "query", message: `Error getting alpla purchase info`, - data: [gpReqCheck.message], - notify: false, + data: gpReqCheck.message as any, + notify: true, }); } @@ -30,7 +30,7 @@ export const gpReqCheck = async (data: GpStatus[]) => { const result = await gpQuery( gpReqCheck.query.replace( "[reqsToCheck]", - data.map((r) => `'${r.req}'`).join(", ") ?? "", + data.map((r) => `'${r.req}'`).join(", ") ?? "xo", ), "Get req info", ); @@ -55,7 +55,7 @@ export const gpReqCheck = async (data: GpStatus[]) => { [Requisition Number] as req ,case when [Workflow Status] = 'recall' then 'returned' else [Workflow Status] end as approvedStatus --,* - from [dbo].[PurchaseRequisitions] where [Requisition Number] in (${missing1Reqs.map((r) => `'${r}'`).join(", ")})`, + from [dbo].[PurchaseRequisitions] where [Requisition Number] in (${missing1Reqs.map((r) => `'${r}'`).join(", ") ?? "xo"})`, "validate req is not in recall", ); @@ -76,7 +76,7 @@ export const gpReqCheck = async (data: GpStatus[]) => { ,PONUMBER ,reqStatus='converted' ,* - from alpla.dbo.sop60100 (nolock) where sopnumbe in (${missing2Reqs.map((r) => `'${r}'`).join(", ")})`, + from alpla.dbo.sop60100 (nolock) where sopnumbe in (${missing2Reqs.map((r) => `'${r}'`).join(", ") ?? "xo"})`, "Get release info", ); @@ -111,7 +111,15 @@ export const gpReqCheck = async (data: GpStatus[]) => { })); return updateData; - } catch (error) { - log.error({ stack: error }); + } catch (error: any) { + return returnFunc({ + success: false, + level: "error", + module: "purchase", + subModule: "gpChecks", + message: error.message, + data: error.stack as any, + notify: true, + }); } }; diff --git a/backend/purchase/purchase.controller.ts b/backend/purchase/purchase.controller.ts index 8018381..3f29c87 100644 --- a/backend/purchase/purchase.controller.ts +++ b/backend/purchase/purchase.controller.ts @@ -39,8 +39,8 @@ export const monitorAlplaPurchase = async () => { module: "purchase", subModule: "query", message: `Error getting alpla purchase info`, - data: [sqlQuery.message], - notify: false, + data: sqlQuery.message as any, + notify: true, }); } @@ -78,7 +78,7 @@ export const monitorAlplaPurchase = async () => { if (error) { log.error( - { error }, + { error, notify: true }, "There was an error adding alpla purchase history", ); } @@ -86,8 +86,10 @@ export const monitorAlplaPurchase = async () => { await delay(500); } } catch (e) { - log.error({ error: e }, "Error occurred while running the monitor job"); - log.error({ error: e }, "Error occurred while running the monitor job"); + log.error( + { error: e, notify: true }, + "Error occurred while running the monitor job", + ); return; } @@ -104,7 +106,7 @@ export const monitorAlplaPurchase = async () => { // if theres no reqs just end meow if (errorReq) { log.error( - { stack: errorReq }, + { stack: errorReq, notify: true }, "There was an error getting history data", ); return; diff --git a/backend/utils/returnHelper.utils.ts b/backend/utils/returnHelper.utils.ts index cf2eaae..1e47ddc 100644 --- a/backend/utils/returnHelper.utils.ts +++ b/backend/utils/returnHelper.utils.ts @@ -33,7 +33,8 @@ interface Data { | "delete" | "printing" | "gpSql" - | "email"; + | "email" + | "gpChecks"; level: "info" | "error" | "debug" | "fatal"; message: string; room?: string;