Skip to content

Hotfix/handling unhandled error in getting mentioned user details #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions connect/connectNotificationServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
}
Expand Down Expand Up @@ -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([]);
Expand Down Expand Up @@ -327,14 +333,15 @@ 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
* @param {Object} data any additional data which is retrieved once
*
* @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);
Expand All @@ -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
Expand Down Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand Down