I am using pg/transaction to handle a complex process. It can be simplified as this:
async() => {
const client = await new Pool().connect();
try {
await client.query("BEGIN");
await client query("query 1");
try {
await client query("query 2");
// Some error happen
} catch(err) {
console.log(err);
}
await client query("query 3");
await client query("COMMIT");
} catch(err) {
await client.query("ROLLBACK");
} finally {
client.release
}
}
The problem is that when query2 returns an error, the client fails to execute query3 even I don't Rollback the process. The error it returns is current transaction is aborted, commands ignored until end of transction block. Is there any way to prevent the transaction from being aborted when a query error happends?