Skip to content

Commit 7a1e5e9

Browse files
author
vikasrohit
authored
Merge pull request #118 from topcoder-platform/hotfix/handling_unhandled_error_in_getting_mentioned_user_details
Hotfix/handling unhandled error in getting mentioned user details
2 parents 8e5c9d9 + 1e6be72 commit 7a1e5e9

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

connect/connectNotificationServer.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ const getTopCoderMembersNotifications = (eventConfig) => {
5757
/**
5858
* Get notifications for mentioned users
5959
*
60+
* @param {Object} logger object used to log in parent thread
6061
* @param {Object} eventConfig event configuration
6162
* @param {Object} message content
6263
*
6364
* @return {Promise} resolves to a list of notifications
6465
*/
65-
const getNotificationsForMentionedUser = (eventConfig, content) => {
66+
const getNotificationsForMentionedUser = (logger, eventConfig, content) => {
6667
if (!eventConfig.toMentionedUsers || !content) {
6768
return Promise.resolve([]);
6869
}
@@ -94,6 +95,11 @@ const getNotificationsForMentionedUser = (eventConfig, content) => {
9495
notification.userId = mentionedUser ? mentionedUser.userId.toString() : notification.userHandle;
9596
});
9697
resolve(notifications);
98+
}).catch((error) => {
99+
if (logger) {
100+
logger.error(error);
101+
}
102+
reject(new Error('Unable to fetch details for mentioned user in the message.'));
97103
});
98104
} else {
99105
resolve([]);
@@ -327,14 +333,15 @@ const getExcludeDraftPhasesNotifications = (eventConfig, project, tags) => {
327333
/**
328334
* Exclude notifications using exclude rules of the event config
329335
*
336+
* @param {Object} logger object used to log in parent thread
330337
* @param {Array} notifications notifications list
331338
* @param {Object} eventConfig event configuration
332339
* @param {Object} message message
333340
* @param {Object} data any additional data which is retrieved once
334341
*
335342
* @returns {Promise} resolves to the list of filtered notifications
336343
*/
337-
const excludeNotifications = (notifications, eventConfig, message, data) => {
344+
const excludeNotifications = (logger, notifications, eventConfig, message, data) => {
338345
// if there are no rules to exclude notifications, just return all of them untouched
339346
if (!eventConfig.exclude) {
340347
return Promise.resolve(notifications);
@@ -355,7 +362,7 @@ const excludeNotifications = (notifications, eventConfig, message, data) => {
355362
return Promise.all([
356363
getNotificationsForTopicStarter(excludeEventConfig, message.topicId),
357364
getNotificationsForUserId(excludeEventConfig, message.userId),
358-
getNotificationsForMentionedUser(excludeEventConfig, message.postContent),
365+
getNotificationsForMentionedUser(logger, excludeEventConfig, message.postContent),
359366
getProjectMembersNotifications(excludeEventConfig, project),
360367
getTopCoderMembersNotifications(excludeEventConfig),
361368
// 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) => {
418425
getNotificationsForTopicStarter(eventConfig, message.topicId),
419426
getNotificationsForUserId(eventConfig, message.userId),
420427
getNotificationsForOriginator(eventConfig, message.originator),
421-
getNotificationsForMentionedUser(eventConfig, message.postContent),
428+
getNotificationsForMentionedUser(logger, eventConfig, message.postContent),
422429
getProjectMembersNotifications(eventConfig, project),
423430
getTopCoderMembersNotifications(eventConfig),
424431
]).then((notificationsPerSource) => {
@@ -427,7 +434,7 @@ const handler = (topic, message, logger, callback) => {
427434
logger.debug('all notifications: ', notificationsPerSource);
428435
return _.uniqBy(_.flatten(notificationsPerSource), 'userId');
429436
}).then((notifications) => (
430-
excludeNotifications(notifications, eventConfig, message, {
437+
excludeNotifications(logger, notifications, eventConfig, message, {
431438
project,
432439
})
433440
)).then((notifications) => {

0 commit comments

Comments
 (0)