Pantheon
Pantheon
KKysely
Created by Pantheon on 9/10/2024 in #help
Roll back transaction prematurely
Given a Transaction, how do I roll it back without throwing an Error inside the execution callback method?
return this._db.transaction().execute(async trx => {
const entryType = await this._db
.selectFrom("updateLogEntryType")
.selectAll()
.where("kind", "=", props.updateKind)
.executeTakeFirst();

if (!entryType) {
logger.error("Unable to create update log with unknown type:", entryType);
// <-- rollback transaction here, without throwing an Error
return new Err("EntryTypeNotFound");
}
);
return this._db.transaction().execute(async trx => {
const entryType = await this._db
.selectFrom("updateLogEntryType")
.selectAll()
.where("kind", "=", props.updateKind)
.executeTakeFirst();

if (!entryType) {
logger.error("Unable to create update log with unknown type:", entryType);
// <-- rollback transaction here, without throwing an Error
return new Err("EntryTypeNotFound");
}
);
9 replies