Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

try/catch email notifications

Blue Mouse70660b798e3c
diff --git a/backend/apps/cloud/src/twoFactorAuth/twoFactorAuth.controller.ts b/backend/apps/cloud/src/twoFactorAuth/twoFactorAuth.controller.ts
index 9c596f846..d08ad1f24 100644
--- a/backend/apps/cloud/src/twoFactorAuth/twoFactorAuth.controller.ts
+++ b/backend/apps/cloud/src/twoFactorAuth/twoFactorAuth.controller.ts
@@ -109,7 +109,11 @@ export class TwoFactorAuthController {
twoFactorRecoveryCode,
})
- await this.mailerService.sendEmail(user.email, LetterTemplate.TwoFAOn)
+ try {
+ await this.mailerService.sendEmail(user.email, LetterTemplate.TwoFAOn)
+ } catch (error) {
+ this.logger.error(error, 'Failed to send 2FA enabled email')
+ }
user.isTwoFactorAuthenticationEnabled = true
@@ -158,13 +162,17 @@ export class TwoFactorAuthController {
throw new BadRequestException('Wrong authentication code')
}
- await this.mailerService.sendEmail(user.email, LetterTemplate.TwoFAOff)
-
await this.userService.update(user.id, {
isTwoFactorAuthenticationEnabled: false,
twoFactorRecoveryCode: null,
twoFactorAuthenticationSecret: null,
})
+
+ try {
+ await this.mailerService.sendEmail(user.email, LetterTemplate.TwoFAOff)
+ } catch (error) {
+ this.logger.error(error, 'Failed to send 2FA disabled email')
+ }
}
@ApiBearerAuth()
diff --git a/backend/apps/community/src/twoFactorAuth/twoFactorAuth.controller.ts b/backend/apps/community/src/twoFactorAuth/twoFactorAuth.controller.ts
index 985603f18..bd706f9da 100644
--- a/backend/apps/community/src/twoFactorAuth/twoFactorAuth.controller.ts
+++ b/backend/apps/community/src/twoFactorAuth/twoFactorAuth.controller.ts
@@ -107,7 +107,11 @@ export class TwoFactorAuthController {
twoFactorRecoveryCode,
})
- await this.mailerService.sendEmail(user.email, LetterTemplate.TwoFAOn)
+ try {
+ await this.mailerService.sendEmail(user.email, LetterTemplate.TwoFAOn)
+ } catch (error) {
+ this.logger.error(error, 'Failed to send 2FA enabled email')
+ }
const authData = await this.authService.generateJwtTokens(user.id, true)
@@ -154,13 +158,17 @@ export class TwoFactorAuthController {
throw new BadRequestException('Wrong authentication code')
}
- await this.mailerService.sendEmail(user.email, LetterTemplate.TwoFAOff)
-
await this.userService.update(user.id, {
isTwoFactorAuthenticationEnabled: 0,
twoFactorRecoveryCode: null,
twoFactorAuthenticationSecret: null,
})
+
+ try {
+ await this.mailerService.sendEmail(user.email, LetterTemplate.TwoFAOff)
+ } catch (error) {
+ this.logger.error(error, 'Failed to send 2FA disabled email')
+ }
}
@ApiBearerAuth()