Tx Rollback meesage

Hey! If I throw a tx.rollback(), is there a way to specify an error message beyond "Rollback" ? I have a transaction in a try/catch block and would love to specify the failed employeeID and throw a custom error message including the employeeID whos transaction failed
2 Replies
Dan
Dan2y ago
Good idea, might be implemented it in the future. For now, you can work around that by declaring a variable outside of the transaction and setting it to the value you need in case of error, something like this:
let failedEmployeeId: number | undefined;

await db.transaction(async (tx) => {
try {
...
} catch (e) {
failedEmployeeId = ...;
tx.rollback();
}
});
let failedEmployeeId: number | undefined;

await db.transaction(async (tx) => {
try {
...
} catch (e) {
failedEmployeeId = ...;
tx.rollback();
}
});
vapor
vaporOP2y ago
Thanks !
Want results from more Discord servers?
Add your server