Skip to content

Commit fc916fd

Browse files
committed
fix(livechat): ensure transaction is aborted only if in progress and simplify room closing check
- Added a check to abort the transaction only if it is currently in progress, improving error handling. - Simplified the condition for throwing an error when closing a room by using optional chaining for better readability.
1 parent 79b93c4 commit fc916fd

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

apps/meteor/app/livechat/server/lib/closeRoom.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export async function closeRoom(params: CloseRoomParams, attempts = 2): Promise<
4242
removedInquiryObj = removedInquiry;
4343
} catch (e) {
4444
logger.error({ err: e, msg: 'Failed to close room', afterAttempts: attempts });
45-
await session.abortTransaction();
45+
if (session.inTransaction()) {
46+
await session.abortTransaction();
47+
}
4648
// Dont propagate transaction errors
4749
if (shouldRetryTransaction(e)) {
4850
if (attempts > 0) {
@@ -186,7 +188,7 @@ async function doCloseRoom(
186188
}
187189

188190
const updatedRoom = await LivechatRooms.closeRoomById(rid, closeData, { session });
189-
if (!params.forceClose && (!updatedRoom || updatedRoom.modifiedCount !== 1)) {
191+
if (!params.forceClose && updatedRoom?.modifiedCount !== 1) {
190192
throw new Error('Error closing room');
191193
}
192194

0 commit comments

Comments
 (0)