@@ -56,12 +56,13 @@ const getTopCoderMembersNotifications = (eventConfig) => {
56
56
/**
57
57
* Get notifications for mentioned users
58
58
*
59
+ * @param {Object } logger object used to log in parent thread
59
60
* @param {Object } eventConfig event configuration
60
61
* @param {Object } message content
61
62
*
62
63
* @return {Promise } resolves to a list of notifications
63
64
*/
64
- const getNotificationsForMentionedUser = ( eventConfig , content ) => {
65
+ const getNotificationsForMentionedUser = ( logger , eventConfig , content ) => {
65
66
if ( ! eventConfig . toMentionedUsers || ! content ) {
66
67
return Promise . resolve ( [ ] ) ;
67
68
}
@@ -93,6 +94,11 @@ const getNotificationsForMentionedUser = (eventConfig, content) => {
93
94
notification . userId = mentionedUser ? mentionedUser . userId . toString ( ) : notification . userHandle ;
94
95
} ) ;
95
96
resolve ( notifications ) ;
97
+ } ) . catch ( ( error ) => {
98
+ if ( logger ) {
99
+ logger . error ( error ) ;
100
+ }
101
+ reject ( new Error ( 'Unable to fetch details for mentioned user in the message.' ) ) ;
96
102
} ) ;
97
103
} else {
98
104
resolve ( [ ] ) ;
@@ -249,14 +255,15 @@ const getNotificationsForTopicStarter = (eventConfig, topicId) => {
249
255
/**
250
256
* Exclude notifications using exclude rules of the event config
251
257
*
258
+ * @param {Object } logger object used to log in parent thread
252
259
* @param {Array } notifications notifications list
253
260
* @param {Object } eventConfig event configuration
254
261
* @param {Object } message message
255
262
* @param {Object } data any additional data which is retrieved once
256
263
*
257
264
* @returns {Promise } resolves to the list of filtered notifications
258
265
*/
259
- const excludeNotifications = ( notifications , eventConfig , message , data ) => {
266
+ const excludeNotifications = ( logger , notifications , eventConfig , message , data ) => {
260
267
// if there are no rules to exclude notifications, just return all of them untouched
261
268
if ( ! eventConfig . exclude ) {
262
269
return Promise . resolve ( notifications ) ;
@@ -275,7 +282,7 @@ const excludeNotifications = (notifications, eventConfig, message, data) => {
275
282
return Promise . all ( [
276
283
getNotificationsForTopicStarter ( excludeEventConfig , message . topicId ) ,
277
284
getNotificationsForUserId ( excludeEventConfig , message . userId ) ,
278
- getNotificationsForMentionedUser ( eventConfig , message . postContent ) ,
285
+ getNotificationsForMentionedUser ( logger , excludeEventConfig , message . postContent ) ,
279
286
getProjectMembersNotifications ( excludeEventConfig , project ) ,
280
287
getTopCoderMembersNotifications ( excludeEventConfig ) ,
281
288
] ) . then ( ( notificationsPerSource ) => (
@@ -335,7 +342,7 @@ const handler = (topic, message, logger, callback) => {
335
342
getNotificationsForTopicStarter ( eventConfig , message . topicId ) ,
336
343
getNotificationsForUserId ( eventConfig , message . userId ) ,
337
344
getNotificationsForOriginator ( eventConfig , message . originator ) ,
338
- getNotificationsForMentionedUser ( eventConfig , message . postContent ) ,
345
+ getNotificationsForMentionedUser ( logger , eventConfig , message . postContent ) ,
339
346
getProjectMembersNotifications ( eventConfig , project ) ,
340
347
getTopCoderMembersNotifications ( eventConfig ) ,
341
348
] ) . then ( ( notificationsPerSource ) => {
@@ -344,7 +351,7 @@ const handler = (topic, message, logger, callback) => {
344
351
logger . debug ( 'all notifications: ' , notificationsPerSource ) ;
345
352
return _ . uniqBy ( _ . flatten ( notificationsPerSource ) , 'userId' ) ;
346
353
} ) . then ( ( notifications ) => (
347
- excludeNotifications ( notifications , eventConfig , message , {
354
+ excludeNotifications ( logger , notifications , eventConfig , message , {
348
355
project,
349
356
} )
350
357
) ) . then ( ( notifications ) => {
0 commit comments