Skip to content

Commit 3929e50

Browse files
author
vikasrohit
authored
Merge pull request #123 from topcoder-platform/hotfix/handling_unhandled_error_in_getting_mentioned_user_details_updated
Hotfix/handling unhandled error in getting mentioned user details updated
2 parents 8fc97a7 + b82b726 commit 3929e50

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

connect/connectNotificationServer.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ const getTopCoderMembersNotifications = (eventConfig) => {
5656
/**
5757
* Get notifications for mentioned users
5858
*
59+
* @param {Object} logger object used to log in parent thread
5960
* @param {Object} eventConfig event configuration
6061
* @param {Object} message content
6162
*
6263
* @return {Promise} resolves to a list of notifications
6364
*/
64-
const getNotificationsForMentionedUser = (eventConfig, content) => {
65+
const getNotificationsForMentionedUser = (logger, eventConfig, content) => {
6566
if (!eventConfig.toMentionedUsers || !content) {
6667
return Promise.resolve([]);
6768
}
@@ -93,6 +94,13 @@ const getNotificationsForMentionedUser = (eventConfig, content) => {
9394
notification.userId = mentionedUser ? mentionedUser.userId.toString() : notification.userHandle;
9495
});
9596
resolve(notifications);
97+
}).catch((error) => {
98+
if (logger) {
99+
logger.error(error);
100+
logger.info('Unable to send notification to mentioned user')
101+
}
102+
//resolves with empty notification which essentially means we are unable to send notification to mentioned user
103+
resolve([]);
96104
});
97105
} else {
98106
resolve([]);
@@ -249,14 +257,15 @@ const getNotificationsForTopicStarter = (eventConfig, topicId) => {
249257
/**
250258
* Exclude notifications using exclude rules of the event config
251259
*
260+
* @param {Object} logger object used to log in parent thread
252261
* @param {Array} notifications notifications list
253262
* @param {Object} eventConfig event configuration
254263
* @param {Object} message message
255264
* @param {Object} data any additional data which is retrieved once
256265
*
257266
* @returns {Promise} resolves to the list of filtered notifications
258267
*/
259-
const excludeNotifications = (notifications, eventConfig, message, data) => {
268+
const excludeNotifications = (logger, notifications, eventConfig, message, data) => {
260269
// if there are no rules to exclude notifications, just return all of them untouched
261270
if (!eventConfig.exclude) {
262271
return Promise.resolve(notifications);
@@ -275,7 +284,7 @@ const excludeNotifications = (notifications, eventConfig, message, data) => {
275284
return Promise.all([
276285
getNotificationsForTopicStarter(excludeEventConfig, message.topicId),
277286
getNotificationsForUserId(excludeEventConfig, message.userId),
278-
getNotificationsForMentionedUser(eventConfig, message.postContent),
287+
getNotificationsForMentionedUser(logger, excludeEventConfig, message.postContent),
279288
getProjectMembersNotifications(excludeEventConfig, project),
280289
getTopCoderMembersNotifications(excludeEventConfig),
281290
]).then((notificationsPerSource) => (
@@ -335,7 +344,7 @@ const handler = (topic, message, logger, callback) => {
335344
getNotificationsForTopicStarter(eventConfig, message.topicId),
336345
getNotificationsForUserId(eventConfig, message.userId),
337346
getNotificationsForOriginator(eventConfig, message.originator),
338-
getNotificationsForMentionedUser(eventConfig, message.postContent),
347+
getNotificationsForMentionedUser(logger, eventConfig, message.postContent),
339348
getProjectMembersNotifications(eventConfig, project),
340349
getTopCoderMembersNotifications(eventConfig),
341350
]).then((notificationsPerSource) => {
@@ -344,7 +353,7 @@ const handler = (topic, message, logger, callback) => {
344353
logger.debug('all notifications: ', notificationsPerSource);
345354
return _.uniqBy(_.flatten(notificationsPerSource), 'userId');
346355
}).then((notifications) => (
347-
excludeNotifications(notifications, eventConfig, message, {
356+
excludeNotifications(logger, notifications, eventConfig, message, {
348357
project,
349358
})
350359
)).then((notifications) => {

0 commit comments

Comments
 (0)