Skip to content

Commit

Permalink
refactor(db/startTransaction): include query and values in errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Mar 6, 2024
1 parent 20083c6 commit d17559b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/database/startTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { PoolConnection } from 'mysql2/promise';
async function runQuery(conn: PoolConnection | null, sql: string, values: CFXParameters) {
[sql, values] = parseArguments(sql, values);

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

const [rows] = await conn.query(sql, values);
return rows;
const [rows] = await conn.query(sql, values);
return rows;
} catch (err: any) {
throw new Error(`Query: ${sql}\n${JSON.stringify(values)}\n${err.message}`);
}
}

export const startTransaction = async (
Expand Down

0 comments on commit d17559b

Please sign in to comment.