I'm encountering an issue with transactions in TypeORM. Here's a snippet of the code causing me trouble:
const someFunction = async () => {
try {
await this.entityManager.transaction(async (manager) => {
//some operations on manager
if (something) {
throw new Error('error')
}
})
} catch (error) {
console.log(error);
}
}
I'm puzzled as to why, when an error is thrown in the if
statement above, it crashes my entire NestJS app and I have to restart it. Could it be that I am mishandling transaction stopping? How can I properly manage transactions and trigger a rollback?
Any help would be greatly appreciated! Thanks!