Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
fix(user): enhance error handling and logging in email sending (#277)
nevin482452393905
diff --git a/project/backend/apps/aitoearn-server/src/user/login.service.ts b/project/backend/apps/aitoearn-server/src/user/login.service.tsindex 9dd16de2..de129be1 100644--- a/project/backend/apps/aitoearn-server/src/user/login.service.ts+++ b/project/backend/apps/aitoearn-server/src/user/login.service.ts@@ -16,58 +16,92 @@ export class LoginService implements OnModuleInit {) { }async sendRegisterMail(mail: string, code: string, name?: string): Promise<boolean> {- let subscriber = await this.subscribersService.findByEmail(mail)- if (!subscriber) {- subscriber = await this.subscribersService.create({- email: mail,- status: SubscriberStatus.ENABLED,- name: name || mail,+ try {+ let subscriber = await this.subscribersService.findByEmail(mail)+ if (!subscriber) {+ subscriber = await this.subscribersService.create({+ email: mail,+ status: SubscriberStatus.ENABLED,+ name: name || mail,+ })+ }++ const res = await this.transactionalService.sendTransactionalMessage({+ subscriber_id: subscriber.id,+ template_id: 5,+ data:+ {+ code,+ },+ subject: 'AiToEarn Verification Code',})+ return res}-- const res = await this.transactionalService.sendTransactionalMessage({- subscriber_id: subscriber.id,- template_id: 5,- data:- {+ catch (error) {+ this.logger.error({+ path: 'sendRegisterMail',+ mail,code,- },- subject: 'AiToEarn Verification Code',- })- return res.data+ name,+ error,+ })+ return false+ }}async sendRepasswordMail(mail: string, code: string): Promise<boolean> {- const subscriber = await this.subscribersService.findByEmail(mail)- if (!subscriber) {- throw new AppException(ResponseCode.UserStatusError, 'The account does not exist')- }- const res = await this.transactionalService.sendTransactionalMessage({- subscriber_id: subscriber.id,- template_id: 6,- data:+ try {+ const subscriber = await this.subscribersService.findByEmail(mail)+ if (!subscriber) {+ throw new AppException(ResponseCode.UserStatusError, 'The account does not exist')+ }+ const res = await this.transactionalService.sendTransactionalMessage({+ subscriber_id: subscriber.id,+ template_id: 6,+ data:{code,},- subject: 'AiToEarn Verification Code',- })- return res.data+ subject: 'AiToEarn Verification Code',+ })+ return res+ }+ catch (error) {+ this.logger.error({+ path: 'sendRepasswordMail',+ mail,+ code,+ error,+ })+ return false+ }}async sendCancelMail(mail: string, code: string): Promise<boolean> {- const subscriber = await this.subscribersService.findByEmail(mail)- if (!subscriber) {- throw new AppException(ResponseCode.UserStatusError, 'The account does not exist')- }- const res = await this.transactionalService.sendTransactionalMessage({- subscriber_id: subscriber.id,- template_id: 7,- data:+ try {+ const subscriber = await this.subscribersService.findByEmail(mail)+ if (!subscriber) {+ throw new AppException(ResponseCode.UserStatusError, 'The account does not exist')+ }+ const res = await this.transactionalService.sendTransactionalMessage({+ subscriber_id: subscriber.id,+ template_id: 7,+ data:{code,},- subject: 'AiToEarn Verification Code',- })- return res.data+ subject: 'AiToEarn Verification Code',+ })+ return res+ }+ catch (error) {+ this.logger.error({+ path: 'sendCancelMail',+ mail,+ code,+ error,+ })+ return false+ }}}diff --git a/project/backend/libs/listmonk/src/api/transactional.service.ts b/project/backend/libs/listmonk/src/api/transactional.service.tsindex 194e0a5e..55f0fa9c 100644--- a/project/backend/libs/listmonk/src/api/transactional.service.ts+++ b/project/backend/libs/listmonk/src/api/transactional.service.ts@@ -4,8 +4,8 @@ import { BaseService } from './base.service'@Injectable()export class TransactionalService extends BaseService {- async sendTransactionalMessage(data: TransactionalMessage): Promise<any> {- const res = await this.request<any>(+ async sendTransactionalMessage(data: TransactionalMessage): Promise<boolean> {+ const res = await this.request<boolean>('/api/tx',{method: 'POST',