Skip to content

Commit 0d01c60

Browse files
author
Vikas Agarwal
committed
Fixing one more Unhandled promise rejection because of wrong data type of userId being passed further for missing users.
1 parent bc9f18c commit 0d01c60

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

connect/connectNotificationServer.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,16 @@ const getNotificationsForMentionedUser = (logger, eventConfig, content) => {
9191
return service.getUsersByHandle(handles).then((users) => {
9292
_.forEach(notifications, (notification) => {
9393
const mentionedUser = _.find(users, { handle: notification.userHandle });
94-
notification.userId = mentionedUser ? mentionedUser.userId.toString() : notification.userHandle;
94+
notification.userId = mentionedUser ? mentionedUser.userId.toString() : null;
95+
if (!notification.userId && logger) {// such notifications would be discarded later after aggregation
96+
logger.info(`Unable to find user with handle ${notification.userHandle}`);
97+
}
9598
});
9699
return Promise.resolve(notifications);
97100
}).catch((error) => {
98101
if (logger) {
99102
logger.error(error);
100-
logger.info('Unable to send notification to mentioned user')
103+
logger.info('Unable to send notification to mentioned user');
101104
}
102105
//resolves with empty notification which essentially means we are unable to send notification to mentioned user
103106
return Promise.resolve([]);
@@ -438,7 +441,7 @@ const handler = (topic, message, logger, callback) => {
438441
project,
439442
})
440443
)).then((notifications) => {
441-
allNotifications = _.filter(notifications, notification => notification.userId !== `${message.initiatorUserId}`);
444+
allNotifications = _.filter(notifications, n => n.userId && n.userId !== `${message.initiatorUserId}`);
442445

443446
if (eventConfig.includeUsers && message[eventConfig.includeUsers] &&
444447
message[eventConfig.includeUsers].length > 0) {

0 commit comments

Comments
 (0)