fix: wrap admin room join logic in try-catch to prevent connection failures and remove redundant comment

This commit is contained in:
pradeepkumar
2026-03-31 05:33:43 +05:30
parent 6056f160ac
commit bd79e09b7f

View File

@@ -112,10 +112,15 @@ export class MessagesGateway implements OnGatewayConnection, OnGatewayDisconnect
this.logger.log(`Client connected successfully: ${client.id} (User: ${userId}, Role: ${payload.role})`);
// Auto-join admin users to admin_room for support chat notifications
if (payload.role === 'ADMIN' || payload.role === 'SUPER_ADMIN') {
client.join('admin_room');
this.logger.log(`Admin ${userId} joined admin_room`);
// Everything below is best-effort — don't let DB errors kill the socket connection
try {
// Auto-join admin users to admin_room for support chat notifications
if (payload.role === 'ADMIN' || payload.role === 'SUPER_ADMIN') {
client.join('admin_room');
this.logger.log(`Admin ${userId} joined admin_room`);
}
} catch (err) {
this.logger.warn(`Failed to join admin room for ${userId}: ${err.message}`);
}
// Update user online status in background (don't await)
@@ -132,7 +137,6 @@ export class MessagesGateway implements OnGatewayConnection, OnGatewayDisconnect
this.messagesService.markPendingMessagesAsDelivered(userId)
.then((results) => {
for (const result of results) {
// Notify each sender that their messages were delivered
const deliveredEvent = {
messageIds: result.messageIds,
conversationId: result.conversationId,