@@ -57,12 +57,13 @@ const getTopCoderMembersNotifications = (eventConfig) => {
57
57
/**
58
58
* Get notifications for mentioned users
59
59
*
60
+ * @param {Object } logger object used to log in parent thread
60
61
* @param {Object } eventConfig event configuration
61
62
* @param {Object } message content
62
63
*
63
64
* @return {Promise } resolves to a list of notifications
64
65
*/
65
- const getNotificationsForMentionedUser = ( eventConfig , content ) => {
66
+ const getNotificationsForMentionedUser = ( logger , eventConfig , content ) => {
66
67
if ( ! eventConfig . toMentionedUsers || ! content ) {
67
68
return Promise . resolve ( [ ] ) ;
68
69
}
@@ -94,6 +95,11 @@ const getNotificationsForMentionedUser = (eventConfig, content) => {
94
95
notification . userId = mentionedUser ? mentionedUser . userId . toString ( ) : notification . userHandle ;
95
96
} ) ;
96
97
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.' ) ) ;
97
103
} ) ;
98
104
} else {
99
105
resolve ( [ ] ) ;
@@ -327,14 +333,15 @@ const getExcludeDraftPhasesNotifications = (eventConfig, project, tags) => {
327
333
/**
328
334
* Exclude notifications using exclude rules of the event config
329
335
*
336
+ * @param {Object } logger object used to log in parent thread
330
337
* @param {Array } notifications notifications list
331
338
* @param {Object } eventConfig event configuration
332
339
* @param {Object } message message
333
340
* @param {Object } data any additional data which is retrieved once
334
341
*
335
342
* @returns {Promise } resolves to the list of filtered notifications
336
343
*/
337
- const excludeNotifications = ( notifications , eventConfig , message , data ) => {
344
+ const excludeNotifications = ( logger , notifications , eventConfig , message , data ) => {
338
345
// if there are no rules to exclude notifications, just return all of them untouched
339
346
if ( ! eventConfig . exclude ) {
340
347
return Promise . resolve ( notifications ) ;
@@ -355,7 +362,7 @@ const excludeNotifications = (notifications, eventConfig, message, data) => {
355
362
return Promise . all ( [
356
363
getNotificationsForTopicStarter ( excludeEventConfig , message . topicId ) ,
357
364
getNotificationsForUserId ( excludeEventConfig , message . userId ) ,
358
- getNotificationsForMentionedUser ( excludeEventConfig , message . postContent ) ,
365
+ getNotificationsForMentionedUser ( logger , excludeEventConfig , message . postContent ) ,
359
366
getProjectMembersNotifications ( excludeEventConfig , project ) ,
360
367
getTopCoderMembersNotifications ( excludeEventConfig ) ,
361
368
// 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) => {
418
425
getNotificationsForTopicStarter ( eventConfig , message . topicId ) ,
419
426
getNotificationsForUserId ( eventConfig , message . userId ) ,
420
427
getNotificationsForOriginator ( eventConfig , message . originator ) ,
421
- getNotificationsForMentionedUser ( eventConfig , message . postContent ) ,
428
+ getNotificationsForMentionedUser ( logger , eventConfig , message . postContent ) ,
422
429
getProjectMembersNotifications ( eventConfig , project ) ,
423
430
getTopCoderMembersNotifications ( eventConfig ) ,
424
431
] ) . then ( ( notificationsPerSource ) => {
@@ -427,7 +434,7 @@ const handler = (topic, message, logger, callback) => {
427
434
logger . debug ( 'all notifications: ' , notificationsPerSource ) ;
428
435
return _ . uniqBy ( _ . flatten ( notificationsPerSource ) , 'userId' ) ;
429
436
} ) . then ( ( notifications ) => (
430
- excludeNotifications ( notifications , eventConfig , message , {
437
+ excludeNotifications ( logger , notifications , eventConfig , message , {
431
438
project,
432
439
} )
433
440
) ) . then ( ( notifications ) => {
0 commit comments