2
0

👷 Surround email alerts sending with try catch

This commit is contained in:
Baptiste Arnaud
2023-06-26 09:40:26 +02:00
parent 0582ca74ac
commit 6430d576ad

View File

@@ -137,10 +137,9 @@ const sendAlertIfLimitReached = async (
console.log( console.log(
`Send almost reached chats limit email to ${to.join(', ')}...` `Send almost reached chats limit email to ${to.join(', ')}...`
) )
try {
await sendAlmostReachedChatsLimitEmail({ await sendAlmostReachedChatsLimitEmail({
to: workspace.members to,
.map((member) => member.user.email)
.filter(isDefined),
usagePercent: Math.round((totalChatsUsed / chatsLimit) * 100), usagePercent: Math.round((totalChatsUsed / chatsLimit) * 100),
chatsLimit, chatsLimit,
url: `https://app.typebot.io/typebots?workspaceId=${workspace.id}`, url: `https://app.typebot.io/typebots?workspaceId=${workspace.id}`,
@@ -149,6 +148,9 @@ const sendAlertIfLimitReached = async (
where: { id: workspace.id }, where: { id: workspace.id },
data: { chatsLimitFirstEmailSentAt: new Date() }, data: { chatsLimitFirstEmailSentAt: new Date() },
}) })
} catch (err) {
console.error(err)
}
} }
if ( if (
@@ -159,6 +161,7 @@ const sendAlertIfLimitReached = async (
const to = workspace.members const to = workspace.members
.map((member) => member.user.email) .map((member) => member.user.email)
.filter(isDefined) .filter(isDefined)
try {
console.log(`Send reached chats limit email to ${to.join(', ')}...`) console.log(`Send reached chats limit email to ${to.join(', ')}...`)
await sendReachedChatsLimitEmail({ await sendReachedChatsLimitEmail({
to, to,
@@ -169,6 +172,9 @@ const sendAlertIfLimitReached = async (
where: { id: workspace.id }, where: { id: workspace.id },
data: { chatsLimitSecondEmailSentAt: new Date() }, data: { chatsLimitSecondEmailSentAt: new Date() },
}) })
} catch (err) {
console.error(err)
}
} }
if (totalChatsUsed > chatsLimit * 3 && workspace.plan === Plan.FREE) { if (totalChatsUsed > chatsLimit * 3 && workspace.plan === Plan.FREE) {