diff --git a/src/database/rawExecute.ts b/src/database/rawExecute.ts index fdb737b..7a5246d 100644 --- a/src/database/rawExecute.ts +++ b/src/database/rawExecute.ts @@ -2,7 +2,7 @@ import { logError, logQuery } from '../logger'; import { CFXCallback, CFXParameters, QueryType } from '../types'; import { parseResponse } from '../utils/parseResponse'; import { executeType, parseExecute } from '../utils/parseExecute'; -import { getConnection } from './connection'; +import { getConnection, MySql } from './connection'; import { setCallback } from '../utils/setCallback'; import { performance } from 'perf_hooks'; import validateResultSet from 'utils/validateResultSet'; @@ -31,9 +31,13 @@ export const rawExecute = async ( return logError(invokingResource, cb, isPromise, err, query, parameters); } - using connection = await getConnection(connectionId); - - if (!connection) return; + let connection: MySql; + try { + connection = await getConnection(connectionId); + } catch (err: any) { + if (!cb) return; + return logError(invokingResource, cb, isPromise, err, query, parameters, true); + } try { const hasProfiler = await runProfiler(connection, invokingResource); diff --git a/src/database/rawQuery.ts b/src/database/rawQuery.ts index c559725..6265181 100644 --- a/src/database/rawQuery.ts +++ b/src/database/rawQuery.ts @@ -4,7 +4,7 @@ import { parseResponse } from '../utils/parseResponse'; import { logQuery, logError } from '../logger'; import type { CFXCallback, CFXParameters } from '../types'; import type { QueryType } from '../types'; -import { getConnection } from './connection'; +import { getConnection, MySql } from './connection'; import { RowDataPacket } from 'mysql2'; import { performance } from 'perf_hooks'; import validateResultSet from 'utils/validateResultSet'; @@ -26,9 +26,13 @@ export const rawQuery = async ( return logError(invokingResource, cb, isPromise, err, query, parameters); } - using connection = await getConnection(connectionId); - - if (!connection) return; + let connection: MySql; + try { + connection = await getConnection(connectionId); + } catch (err: any) { + if (!cb) return; + return logError(invokingResource, cb, isPromise, err, query, parameters, true); + } try { const hasProfiler = await runProfiler(connection, invokingResource); diff --git a/src/database/rawTransaction.ts b/src/database/rawTransaction.ts index 98b8762..865300d 100644 --- a/src/database/rawTransaction.ts +++ b/src/database/rawTransaction.ts @@ -1,4 +1,4 @@ -import { getConnection } from './connection'; +import { getConnection, MySql } from './connection'; import { logError, logger, logQuery } from '../logger'; import { CFXCallback, CFXParameters, TransactionQuery } from '../types'; import { parseTransaction } from '../utils/parseTransaction'; @@ -28,7 +28,13 @@ export const rawTransaction = async ( return logError(invokingResource, cb, isPromise, err); } - using connection = await getConnection(); + let connection: MySql; + try { + connection = await getConnection(); + } catch (err: any) { + if (!cb) return; + return logError(invokingResource, cb, isPromise, err, queries.toString(), parameters, true); + } if (!connection) return; diff --git a/src/logger/index.ts b/src/logger/index.ts index fbf9410..32165a0 100644 --- a/src/logger/index.ts +++ b/src/logger/index.ts @@ -53,8 +53,9 @@ export function logError( metadata: err, }); - if (cb && isPromise) { + if (cb) { try { + if(isPromise) return cb(null); return cb(null, output); } catch (e) {}