Skip to content

Commit 62e0944

Browse files
committed
slack fails silently so endpoints don't fail bc of external api
1 parent 1a9aa1d commit 62e0944

5 files changed

Lines changed: 74 additions & 153 deletions

File tree

src/backend/src/integrations/slack.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export const sendMessage = async (slackId: string, message: string, link?: strin
2828

2929
return response && response.channel && response.ts && { channelId: response.channel, ts: response.ts };
3030
} catch (error) {
31-
throw new HttpException(500, 'Error sending slack message, reason: ' + (error as any).data.error);
31+
console.error('Failed to send Slack message:', (error as any)?.data?.error ?? error);
32+
return undefined;
3233
}
3334
};
3435

@@ -61,7 +62,8 @@ export const replyToMessageInThread = async (
6162
blocks: [block]
6263
});
6364
} catch (error) {
64-
throw new HttpException(500, 'Error sending slack reply to thread, reason: ' + (error as any).data.error);
65+
console.error('Failed to send Slack thread reply:', (error as any)?.data?.error ?? error);
66+
return undefined;
6567
}
6668
};
6769

@@ -94,7 +96,8 @@ export const editMessage = async (
9496
blocks: [block]
9597
});
9698
} catch (error) {
97-
throw new HttpException(500, 'Error sending slack reply to thread, reason: ' + (error as any).data.error);
99+
console.error('Failed to edit Slack message:', (error as any)?.data?.error ?? error);
100+
return undefined;
98101
}
99102
};
100103

@@ -116,7 +119,8 @@ export const reactToMessage = async (slackId: string, parentTimestamp: string, e
116119
name: emoji
117120
});
118121
} catch (error) {
119-
throw new HttpException(500, 'Error reacting to slack message, reason: ' + (error as any).data.error);
122+
console.error('Failed to react to Slack message:', (error as any)?.data?.error ?? error);
123+
return undefined;
120124
}
121125
};
122126

src/backend/src/services/calendar.services.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -514,17 +514,12 @@ export default class CalendarService {
514514
if (newEvent.status === Event_Status.UNCONFIRMED) {
515515
for (const memberUserSetting of memberUserSettings) {
516516
if (memberUserSetting.slackId) {
517-
try {
518-
// For each project associated with this event
519-
await sendSlackEventConfirmNotification(
520-
memberUserSetting.slackId,
521-
newEvent.eventId,
522-
newEvent.title,
523-
projects.map((project) => project.wbsElement.name).join(', ')
524-
);
525-
} catch (err: unknown) {
526-
console.error('Failed to send slack notification for event:', err);
527-
}
517+
await sendSlackEventConfirmNotification(
518+
memberUserSetting.slackId,
519+
newEvent.eventId,
520+
newEvent.title,
521+
projects.map((project) => project.wbsElement.name).join(', ')
522+
);
528523
}
529524
}
530525
}
@@ -535,17 +530,13 @@ export default class CalendarService {
535530
for (const project of projects) {
536531
const projectTeams = project.teams;
537532
if (projectTeams.length > 0) {
538-
try {
539-
await sendSlackEventNotifications(
540-
projectTeams,
541-
createdEvent,
542-
submitter,
543-
workPackageNames,
544-
project.wbsElement.name
545-
);
546-
} catch (err: unknown) {
547-
console.error('Failed to send slack notification for event:', err);
548-
}
533+
await sendSlackEventNotifications(
534+
projectTeams,
535+
createdEvent,
536+
submitter,
537+
workPackageNames,
538+
project.wbsElement.name
539+
);
549540
}
550541
}
551542
}

src/backend/src/services/reimbursement-requests.services.ts

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,15 +1288,11 @@ export default class ReimbursementRequestService {
12881288
...getReimbursementStatusQueryArgs(organization.organizationId)
12891289
});
12901290

1291-
try {
1292-
await sendPendingSaboSubmissionNotification(
1293-
reimbursementRequest.notificationSlackThreads,
1294-
submitter.userId,
1295-
reimbursementRequest.recipientId
1296-
);
1297-
} catch (e: unknown) {
1298-
console.error('Error sending pending SABO submission notification:', e);
1299-
}
1291+
await sendPendingSaboSubmissionNotification(
1292+
reimbursementRequest.notificationSlackThreads,
1293+
submitter.userId,
1294+
reimbursementRequest.recipientId
1295+
);
13001296

13011297
return reimbursementStatusTransformer(reimbursementStatus);
13021298
}
@@ -1370,11 +1366,7 @@ export default class ReimbursementRequestService {
13701366
...getReimbursementStatusQueryArgs(organization.organizationId)
13711367
});
13721368

1373-
try {
1374-
await sendSubmittedToSaboNotification(reimbursementRequest.notificationSlackThreads);
1375-
} catch (e: unknown) {
1376-
console.error('Error sending submitted to SABO notification:', e);
1377-
}
1369+
await sendSubmittedToSaboNotification(reimbursementRequest.notificationSlackThreads);
13781370

13791371
return reimbursementStatusTransformer(reimbursementStatus);
13801372
}
@@ -1443,11 +1435,7 @@ export default class ReimbursementRequestService {
14431435
'Reimbursement Request successfully updated, however no slack message was sent as recipient is missing their settings!'
14441436
);
14451437

1446-
try {
1447-
await sendReimbursementRequestDeniedNotification(recipientSettings.slackId, reimbursementRequestId);
1448-
} catch (e: unknown) {
1449-
console.error('Error sending reimbursement request denied notification:', e);
1450-
}
1438+
await sendReimbursementRequestDeniedNotification(recipientSettings.slackId, reimbursementRequestId);
14511439

14521440
return reimbursementStatusTransformer(reimbursementStatus);
14531441
}
@@ -1734,14 +1722,10 @@ export default class ReimbursementRequestService {
17341722
...getReimbursementStatusQueryArgs(organization.organizationId)
17351723
});
17361724

1737-
try {
1738-
await sendReimbursementRequestPendingFinanceNotification(
1739-
reimbursementRequest.notificationSlackThreads,
1740-
reimbursementRequest.assigneeId
1741-
);
1742-
} catch (e: unknown) {
1743-
console.error('Error sending reimbursement request pending finance notification:', e);
1744-
}
1725+
await sendReimbursementRequestPendingFinanceNotification(
1726+
reimbursementRequest.notificationSlackThreads,
1727+
reimbursementRequest.assigneeId
1728+
);
17451729

17461730
return reimbursementStatusTransformer(updatedReimbursementStatus);
17471731
}
@@ -1795,11 +1779,7 @@ export default class ReimbursementRequestService {
17951779
...getReimbursementStatusQueryArgs(organization.organizationId)
17961780
});
17971781

1798-
try {
1799-
await sendReimbursementRequestChangesRequestedNotification(reimbursementRequest.notificationSlackThreads, user.userId);
1800-
} catch (e: unknown) {
1801-
console.error('Error sending reimbursement request changes requested notification:', e);
1802-
}
1782+
await sendReimbursementRequestChangesRequestedNotification(reimbursementRequest.notificationSlackThreads, user.userId);
18031783

18041784
return reimbursementStatusTransformer(deletedStatus);
18051785
}

src/backend/src/utils/change-requests.utils.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -608,18 +608,12 @@ export const sendCRSubmitterReviewedNotification = async (
608608
) => {
609609
const creatorUserSettings = await prisma.user_Settings.findUnique({ where: { userId: foundCR.submitterId } });
610610
if (creatorUserSettings && creatorUserSettings.slackId) {
611-
try {
612-
await sendSlackCRReviewedNotification(
613-
creatorUserSettings.slackId,
614-
foundCR.crId,
615-
foundCR.identifier,
616-
foundCR.reviewNotes
617-
);
618-
} catch (err: unknown) {
619-
if (err instanceof Error) {
620-
throw new HttpException(500, `Failed to send slack notification: ${err.message}`);
621-
}
622-
}
611+
await sendSlackCRReviewedNotification(
612+
creatorUserSettings.slackId,
613+
foundCR.crId,
614+
foundCR.identifier,
615+
foundCR.reviewNotes
616+
);
623617
}
624618
};
625619

src/backend/src/utils/slack.utils.ts

Lines changed: 35 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,16 @@ export const sendReimbursementRequestCreatedNotificationAndCreateMessageInfo = a
147147

148148
if (!financeTeam) throw new HttpException(500, 'Finance team does not exist!');
149149

150-
try {
151-
const messageInfo = await sendMessage(financeTeam.slackId, msg, link, linkButtonText);
152-
if (!messageInfo) return; // Not on prod
153-
154-
await prisma.message_Info.create({
155-
data: {
156-
reimbursementRequestId: requestId,
157-
channelId: messageInfo.channelId,
158-
timestamp: messageInfo.ts
159-
}
160-
});
161-
} catch (error: unknown) {
162-
if (error instanceof Error) {
163-
throw new HttpException(500, `Failed to send slack notification: ${error.message}`);
150+
const messageInfo = await sendMessage(financeTeam.slackId, msg, link, linkButtonText);
151+
if (!messageInfo) return;
152+
153+
await prisma.message_Info.create({
154+
data: {
155+
reimbursementRequestId: requestId,
156+
channelId: messageInfo.channelId,
157+
timestamp: messageInfo.ts
164158
}
165-
}
159+
});
166160
};
167161

168162
/**
@@ -177,26 +171,14 @@ export const sendReimbursementRequestDeniedNotification = async (slackId: string
177171
const link = `https://finishlinebyner.com/finance/reimbursement-requests/${requestId}`;
178172
const linkButtonText = 'View Reimbursement Request';
179173

180-
try {
181-
await sendMessage(slackId, msg, link, linkButtonText);
182-
} catch (error: unknown) {
183-
if (error instanceof Error) {
184-
throw new HttpException(500, `Failed to send slack notification: ${error.message}`);
185-
}
186-
}
174+
await sendMessage(slackId, msg, link, linkButtonText);
187175
};
188176

189177
export const sendThreadResponse = async (threads: SlackMessageThread[], message: string) => {
190178
if (process.env.NODE_ENV !== 'production' && !DEV_TESTING_OVERRIDE) return; // don't send msgs unless in prod
191-
try {
192-
if (threads && threads.length !== 0) {
193-
const msgs = threads.map((thread) => replyToMessageInThread(thread.channelId, thread.timestamp, message));
194-
await Promise.all(msgs);
195-
}
196-
} catch (err: unknown) {
197-
if (err instanceof Error) {
198-
throw new HttpException(500, `Failed to send slack notifications: ${err.message}`);
199-
}
179+
if (threads && threads.length !== 0) {
180+
const msgs = threads.map((thread) => replyToMessageInThread(thread.channelId, thread.timestamp, message));
181+
await Promise.all(msgs);
200182
}
201183
};
202184

@@ -257,13 +239,7 @@ export const sendSlackEventConfirmNotification = async (
257239
: `http://localhost:3000/calendar/event/${eventId}`;
258240
const linkButtonText = 'Confirm Availability';
259241

260-
try {
261-
await sendMessage(slackId, msg, fullLink, linkButtonText);
262-
} catch (error: unknown) {
263-
if (error instanceof Error) {
264-
throw new HttpException(500, `Failed to send slack notification: ${error.message}`);
265-
}
266-
}
242+
await sendMessage(slackId, msg, fullLink, linkButtonText);
267243
};
268244

269245
/**
@@ -390,31 +366,19 @@ export const sendEventUserConfirmationToThread = async (threads: SlackMessageThr
390366
if (process.env.NODE_ENV !== 'production' && !DEV_TESTING_OVERRIDE) return; // don't send msgs unless in prod
391367
const slackPing = userToSlackPing(submitter);
392368
const fullMsg = `${slackPing} confirmed their availability!`;
393-
try {
394-
if (threads && threads.length !== 0) {
395-
const msgs = threads.map((thread) => replyToMessageInThread(thread.channelId, thread.timestamp, fullMsg));
396-
await Promise.all(msgs);
397-
}
398-
} catch (err: unknown) {
399-
if (err instanceof Error) {
400-
throw new HttpException(500, `Failed to send slack notification: ${err.message}`);
401-
}
369+
if (threads && threads.length !== 0) {
370+
const msgs = threads.map((thread) => replyToMessageInThread(thread.channelId, thread.timestamp, fullMsg));
371+
await Promise.all(msgs);
402372
}
403373
};
404374

405375
export const sendEventConfirmationToThread = async (threads: SlackMessageThread[], submitter: UserWithSettings) => {
406376
if (process.env.NODE_ENV !== 'production' && !DEV_TESTING_OVERRIDE) return; // don't send msgs unless in prod
407377
const slackPing = userToSlackPing(submitter);
408378
const fullMsg = `${slackPing} All of the required attendees have confirmed their availability!`;
409-
try {
410-
if (threads && threads.length !== 0) {
411-
const msgs = threads.map((thread) => replyToMessageInThread(thread.channelId, thread.timestamp, fullMsg));
412-
await Promise.all(msgs);
413-
}
414-
} catch (err: unknown) {
415-
if (err instanceof Error) {
416-
throw new HttpException(500, `Failed to send slack notification: ${err.message}`);
417-
}
379+
if (threads && threads.length !== 0) {
380+
const msgs = threads.map((thread) => replyToMessageInThread(thread.channelId, thread.timestamp, fullMsg));
381+
await Promise.all(msgs);
418382
}
419383
};
420384

@@ -456,19 +420,13 @@ export const sendEventScheduledSlackNotif = async (threads: SlackMessageThread[]
456420
const docLink = event.questionDocumentLink ? `<${event.questionDocumentLink}|Doc Link>` : '';
457421
const threadMsg = `This event has been Scheduled! \n` + docLink;
458422

459-
try {
460-
if (threads && threads.length !== 0) {
461-
const msgs = threads.map((thread) => editMessage(thread.channelId, thread.timestamp, msg));
462-
await Promise.all(msgs);
463-
const threadMsgs = threads.map((thread) => replyToMessageInThread(thread.channelId, thread.timestamp, threadMsg));
464-
await Promise.all(threadMsgs);
465-
const reactions = threads.map((thread) => reactToMessage(thread.channelId, thread.timestamp, 'calendar'));
466-
await Promise.all(reactions);
467-
}
468-
} catch (err: unknown) {
469-
if (err instanceof Error) {
470-
throw new HttpException(500, `Failed to send slack notification: ${err.message}`);
471-
}
423+
if (threads && threads.length !== 0) {
424+
const msgs = threads.map((thread) => editMessage(thread.channelId, thread.timestamp, msg));
425+
await Promise.all(msgs);
426+
const threadMsgs = threads.map((thread) => replyToMessageInThread(thread.channelId, thread.timestamp, threadMsg));
427+
await Promise.all(threadMsgs);
428+
const reactions = threads.map((thread) => reactToMessage(thread.channelId, thread.timestamp, 'calendar'));
429+
await Promise.all(reactions);
472430
}
473431
};
474432

@@ -509,20 +467,14 @@ export const sendSlackCRStatusToThread = async (
509467
const fullMsg = `This Change Request was ${approved ? 'approved! :tada:' : 'denied.'} Click the link to view.`;
510468
const fullLink = `https://finishlinebyner.com/cr/${crId}`;
511469
const btnText = `View CR#${identifier}`;
512-
try {
513-
if (threads && threads.length !== 0) {
514-
const msgs = threads.map((thread) =>
515-
replyToMessageInThread(thread.channelId, thread.timestamp, fullMsg, fullLink, btnText)
516-
);
517-
const reactions = threads.map((thread) =>
518-
reactToMessage(thread.channelId, thread.timestamp, approved ? 'white_check_mark' : 'x')
519-
);
520-
await Promise.all([...msgs, ...reactions]);
521-
}
522-
} catch (err: unknown) {
523-
if (err instanceof Error) {
524-
throw new HttpException(500, `Failed to send slack notification: ${err.message}`);
525-
}
470+
if (threads && threads.length !== 0) {
471+
const msgs = threads.map((thread) =>
472+
replyToMessageInThread(thread.channelId, thread.timestamp, fullMsg, fullLink, btnText)
473+
);
474+
const reactions = threads.map((thread) =>
475+
reactToMessage(thread.channelId, thread.timestamp, approved ? 'white_check_mark' : 'x')
476+
);
477+
await Promise.all([...msgs, ...reactions]);
526478
}
527479
};
528480

0 commit comments

Comments
 (0)