From 1e1fe61bcc37d1fe3d1a9828e7d2a6c6e7693a7f Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Wed, 17 Nov 2021 14:26:38 -0600 Subject: [PATCH] Await promise to handle error when attempting to transfer a room --- app/livechat/server/lib/Livechat.js | 2 +- app/livechat/server/lib/stream/agentStatus.ts | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/livechat/server/lib/Livechat.js b/app/livechat/server/lib/Livechat.js index aa399564bfa5..6ccd54915287 100644 --- a/app/livechat/server/lib/Livechat.js +++ b/app/livechat/server/lib/Livechat.js @@ -598,7 +598,7 @@ export const Livechat = { const user = Users.findOneById(userId); const { _id, username, name } = user; const transferredBy = normalizeTransferredByData({ _id, username, name }, room); - this.transfer(room, guest, { roomId: room._id, transferredBy, departmentId: guest.department }); + Promise.await(this.transfer(room, guest, { roomId: room._id, transferredBy, departmentId: guest.department })); }); }, diff --git a/app/livechat/server/lib/stream/agentStatus.ts b/app/livechat/server/lib/stream/agentStatus.ts index ed46bacbd0f8..12985a42f58d 100644 --- a/app/livechat/server/lib/stream/agentStatus.ts +++ b/app/livechat/server/lib/stream/agentStatus.ts @@ -2,6 +2,9 @@ import { Meteor } from 'meteor/meteor'; import { Livechat } from '../Livechat'; import { settings } from '../../../../settings/server'; +import { Logger } from '../../../../logger/server'; + +const logger = new Logger('AgentStatusWatcher'); export let monitorAgents = false; let actionTimeout = 60000; @@ -64,12 +67,19 @@ export const onlineAgents = { onlineAgents.users.delete(userId); onlineAgents.queue.delete(userId); - if (action === 'close') { - return Livechat.closeOpenChats(userId, comment); - } + try { + if (action === 'close') { + return Livechat.closeOpenChats(userId, comment); + } - if (action === 'forward') { - return Livechat.forwardOpenChats(userId); + if (action === 'forward') { + return Livechat.forwardOpenChats(userId); + } + } catch (e) { + logger.error({ + msg: `Cannot perform action ${ action }`, + err: e, + }); } }), };