Skip to content

Commit

Permalink
Clean-up error messages around retry.
Browse files Browse the repository at this point in the history
  • Loading branch information
aboodman committed Feb 22, 2024
1 parent 3e9b6d1 commit 00d9dbb
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions backend/pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,15 @@ export async function withExecutor<R>(
console.log("pool.connect took", Date.now() - startConnect);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const executor = async (sql: string, params?: any[]) => {
try {
const start = Date.now();
const result = await client.query(sql, params);
console.log(
"Db query took " +
(Date.now() - start) +
"ms. SQL: " +
sql.substring(0, Math.min(sql.length, 150))
);
return result;
} catch (e) {
console.error("Error executing SQL", sql, e);
throw e;
}
const start = Date.now();
const result = await client.query(sql, params);
console.log(
"Db query took " +
(Date.now() - start) +
"ms. SQL: " +
sql.substring(0, Math.min(sql.length, 150))
);
return result;
};

try {
Expand Down Expand Up @@ -90,7 +85,7 @@ async function transactWithExecutor<R>(
await executor("commit");
return r;
} catch (e) {
console.log("caught error", e, "rolling back");
console.log(`caught error ${e} rolling back`);
await executor("rollback");
throw e;
}
Expand Down

0 comments on commit 00d9dbb

Please sign in to comment.