From 96eb7f36dcdbff68dcfaac3ad56f43c24985fbcb Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Thu, 24 Apr 2025 12:55:40 -0400 Subject: [PATCH] gp connection error catch --- database/getContractTransactions.js | 2 +- database/getContractTransactions.ts | 2 +- handlers/contracts-post/doGetDynamicsGPDocument.js | 2 +- handlers/contracts-post/doGetDynamicsGPDocument.ts | 2 +- ...ctions.dynamicsGP.d.ts => dynamicsGp.helpers.d.ts} | 0 ...{functions.dynamicsGP.js => dynamicsGp.helpers.js} | 11 ++++++++++- ...{functions.dynamicsGP.ts => dynamicsGp.helpers.ts} | 11 ++++++++++- 7 files changed, 24 insertions(+), 6 deletions(-) rename helpers/{functions.dynamicsGP.d.ts => dynamicsGp.helpers.d.ts} (100%) rename helpers/{functions.dynamicsGP.js => dynamicsGp.helpers.js} (92%) rename helpers/{functions.dynamicsGP.ts => dynamicsGp.helpers.ts} (92%) diff --git a/database/getContractTransactions.js b/database/getContractTransactions.js index ab18419a..f0248c0a 100644 --- a/database/getContractTransactions.js +++ b/database/getContractTransactions.js @@ -2,7 +2,7 @@ import { dateIntegerToString, timeIntegerToString } from '@cityssm/utils-datetim import sqlite from 'better-sqlite3'; import { getConfigProperty } from '../helpers/config.helpers.js'; import { sunriseDB } from '../helpers/database.helpers.js'; -import { getDynamicsGPDocument } from '../helpers/functions.dynamicsGP.js'; +import { getDynamicsGPDocument } from '../helpers/dynamicsGp.helpers.js'; export default async function GetContractTransactions(contractId, options, connectedDatabase) { const database = connectedDatabase ?? sqlite(sunriseDB, { readonly: true }); database.function('userFn_dateIntegerToString', dateIntegerToString); diff --git a/database/getContractTransactions.ts b/database/getContractTransactions.ts index 55672da7..2b3cc2a1 100644 --- a/database/getContractTransactions.ts +++ b/database/getContractTransactions.ts @@ -6,7 +6,7 @@ import sqlite from 'better-sqlite3' import { getConfigProperty } from '../helpers/config.helpers.js' import { sunriseDB } from '../helpers/database.helpers.js' -import { getDynamicsGPDocument } from '../helpers/functions.dynamicsGP.js' +import { getDynamicsGPDocument } from '../helpers/dynamicsGp.helpers.js' import type { ContractTransaction } from '../types/record.types.js' export default async function GetContractTransactions( diff --git a/handlers/contracts-post/doGetDynamicsGPDocument.js b/handlers/contracts-post/doGetDynamicsGPDocument.js index 769a82cc..9c5aa003 100644 --- a/handlers/contracts-post/doGetDynamicsGPDocument.js +++ b/handlers/contracts-post/doGetDynamicsGPDocument.js @@ -1,5 +1,5 @@ /* eslint-disable @eslint-community/eslint-comments/disable-enable-pair, unicorn/filename-case */ -import { getDynamicsGPDocument } from '../../helpers/functions.dynamicsGP.js'; +import { getDynamicsGPDocument } from '../../helpers/dynamicsGp.helpers.js'; export default async function handler(request, response) { const externalReceiptNumber = request.body.externalReceiptNumber; const dynamicsGPDocument = await getDynamicsGPDocument(externalReceiptNumber); diff --git a/handlers/contracts-post/doGetDynamicsGPDocument.ts b/handlers/contracts-post/doGetDynamicsGPDocument.ts index d52c7a34..3f4e68b2 100644 --- a/handlers/contracts-post/doGetDynamicsGPDocument.ts +++ b/handlers/contracts-post/doGetDynamicsGPDocument.ts @@ -2,7 +2,7 @@ import type { Request, Response } from 'express' -import { getDynamicsGPDocument } from '../../helpers/functions.dynamicsGP.js' +import { getDynamicsGPDocument } from '../../helpers/dynamicsGp.helpers.js' export default async function handler( request: Request, diff --git a/helpers/functions.dynamicsGP.d.ts b/helpers/dynamicsGp.helpers.d.ts similarity index 100% rename from helpers/functions.dynamicsGP.d.ts rename to helpers/dynamicsGp.helpers.d.ts diff --git a/helpers/functions.dynamicsGP.js b/helpers/dynamicsGp.helpers.js similarity index 92% rename from helpers/functions.dynamicsGP.js rename to helpers/dynamicsGp.helpers.js index 223fa6fa..d2c6bcf4 100644 --- a/helpers/functions.dynamicsGP.js +++ b/helpers/dynamicsGp.helpers.js @@ -1,5 +1,8 @@ import { DynamicsGP } from '@cityssm/dynamics-gp'; +import Debug from 'debug'; +import { DEBUG_NAMESPACE } from '../debug.config.js'; import { getConfigProperty } from './config.helpers.js'; +const debug = Debug(`${DEBUG_NAMESPACE}:dynamicsGP.helpers:${process.pid}`); let gp; if (getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { gp = new DynamicsGP(getConfigProperty('settings.dynamicsGP.mssqlConfig')); @@ -10,7 +13,13 @@ export async function getDynamicsGPDocument(documentNumber) { } let document; for (const lookupType of getConfigProperty('settings.dynamicsGP.lookupOrder')) { - document = await _getDynamicsGPDocument(documentNumber, lookupType); + try { + document = await _getDynamicsGPDocument(documentNumber, lookupType); + } + catch (error) { + debug(`Error fetching Dynamics GP document for ${lookupType}:`); + debug(error); + } if (document !== undefined) { break; } diff --git a/helpers/functions.dynamicsGP.ts b/helpers/dynamicsGp.helpers.ts similarity index 92% rename from helpers/functions.dynamicsGP.ts rename to helpers/dynamicsGp.helpers.ts index aa3497e8..5150fce6 100644 --- a/helpers/functions.dynamicsGP.ts +++ b/helpers/dynamicsGp.helpers.ts @@ -4,12 +4,16 @@ import { type GPInvoice, DynamicsGP } from '@cityssm/dynamics-gp' +import Debug from 'debug' +import { DEBUG_NAMESPACE } from '../debug.config.js' import type { DynamicsGPLookup } from '../types/config.types.js' import type { DynamicsGPDocument } from '../types/record.types.js' import { getConfigProperty } from './config.helpers.js' +const debug = Debug(`${DEBUG_NAMESPACE}:dynamicsGP.helpers:${process.pid}`) + let gp: DynamicsGP if (getConfigProperty('settings.dynamicsGP.integrationIsEnabled')) { @@ -28,7 +32,12 @@ export async function getDynamicsGPDocument( for (const lookupType of getConfigProperty( 'settings.dynamicsGP.lookupOrder' )) { - document = await _getDynamicsGPDocument(documentNumber, lookupType) + try { + document = await _getDynamicsGPDocument(documentNumber, lookupType) + } catch (error) { + debug(`Error fetching Dynamics GP document for ${lookupType}:`) + debug(error) + } if (document !== undefined) { break