gp connection error catch

pull/11/head
Dan Gowans 2025-04-24 12:55:40 -04:00
parent 4f6fc87e05
commit 96eb7f36dc
7 changed files with 24 additions and 6 deletions

View File

@ -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);

View File

@ -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(

View File

@ -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);

View File

@ -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<unknown, unknown, { externalReceiptNumber: string }>,

View File

@ -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;
}

View File

@ -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