diff --git a/connect/connectNotificationServer.js b/connect/connectNotificationServer.js index 0b42233..dd783fd 100644 --- a/connect/connectNotificationServer.js +++ b/connect/connectNotificationServer.js @@ -57,12 +57,13 @@ const getTopCoderMembersNotifications = (eventConfig) => { /** * Get notifications for mentioned users * + * @param {Object} logger object used to log in parent thread * @param {Object} eventConfig event configuration * @param {Object} message content * * @return {Promise} resolves to a list of notifications */ -const getNotificationsForMentionedUser = (eventConfig, content) => { +const getNotificationsForMentionedUser = (logger, eventConfig, content) => { if (!eventConfig.toMentionedUsers || !content) { return Promise.resolve([]); } @@ -94,6 +95,11 @@ const getNotificationsForMentionedUser = (eventConfig, content) => { notification.userId = mentionedUser ? mentionedUser.userId.toString() : notification.userHandle; }); resolve(notifications); + }).catch((error) => { + if (logger) { + logger.error(error); + } + reject(new Error('Unable to fetch details for mentioned user in the message.')); }); } else { resolve([]); @@ -327,6 +333,7 @@ const getExcludeDraftPhasesNotifications = (eventConfig, project, tags) => { /** * Exclude notifications using exclude rules of the event config * + * @param {Object} logger object used to log in parent thread * @param {Array} notifications notifications list * @param {Object} eventConfig event configuration * @param {Object} message message @@ -334,7 +341,7 @@ const getExcludeDraftPhasesNotifications = (eventConfig, project, tags) => { * * @returns {Promise} resolves to the list of filtered notifications */ -const excludeNotifications = (notifications, eventConfig, message, data) => { +const excludeNotifications = (logger, notifications, eventConfig, message, data) => { // if there are no rules to exclude notifications, just return all of them untouched if (!eventConfig.exclude) { return Promise.resolve(notifications); @@ -355,7 +362,7 @@ const excludeNotifications = (notifications, eventConfig, message, data) => { return Promise.all([ getNotificationsForTopicStarter(excludeEventConfig, message.topicId), getNotificationsForUserId(excludeEventConfig, message.userId), - getNotificationsForMentionedUser(excludeEventConfig, message.postContent), + getNotificationsForMentionedUser(logger, excludeEventConfig, message.postContent), getProjectMembersNotifications(excludeEventConfig, project), getTopCoderMembersNotifications(excludeEventConfig), // these are special exclude rules which are only working for excluding notifications but not including @@ -418,7 +425,7 @@ const handler = (topic, message, logger, callback) => { getNotificationsForTopicStarter(eventConfig, message.topicId), getNotificationsForUserId(eventConfig, message.userId), getNotificationsForOriginator(eventConfig, message.originator), - getNotificationsForMentionedUser(eventConfig, message.postContent), + getNotificationsForMentionedUser(logger, eventConfig, message.postContent), getProjectMembersNotifications(eventConfig, project), getTopCoderMembersNotifications(eventConfig), ]).then((notificationsPerSource) => { @@ -427,7 +434,7 @@ const handler = (topic, message, logger, callback) => { logger.debug('all notifications: ', notificationsPerSource); return _.uniqBy(_.flatten(notificationsPerSource), 'userId'); }).then((notifications) => ( - excludeNotifications(notifications, eventConfig, message, { + excludeNotifications(logger, notifications, eventConfig, message, { project, }) )).then((notifications) => {