Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit d17559b

Browse files
committed
refactor(db/startTransaction): include query and values in errors
1 parent 20083c6 commit d17559b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/database/startTransaction.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import { PoolConnection } from 'mysql2/promise';
77
async function runQuery(conn: PoolConnection | null, sql: string, values: CFXParameters) {
88
[sql, values] = parseArguments(sql, values);
99

10-
if (!conn)
11-
throw new Error(
12-
`Query: ${sql}\n${JSON.stringify(values)}\nConnection used by transaction timed out after 30 seconds.`
13-
);
10+
try {
11+
if (!conn) throw new Error(`Connection used by transaction timed out after 30 seconds.`);
1412

15-
const [rows] = await conn.query(sql, values);
16-
return rows;
13+
const [rows] = await conn.query(sql, values);
14+
return rows;
15+
} catch (err: any) {
16+
throw new Error(`Query: ${sql}\n${JSON.stringify(values)}\n${err.message}`);
17+
}
1718
}
1819

1920
export const startTransaction = async (

0 commit comments

Comments
 (0)