fix: add error log to whatsapp service

pull/128/head 1.4.6-alpha.1
shancheas 2025-01-30 07:01:52 +07:00
parent 7953c7dbbd
commit 46caaba6bd
1 changed files with 17 additions and 6 deletions

View File

@ -12,6 +12,7 @@ import {
} from './whatsapp.constant';
import axios from 'axios';
import { Logger } from '@nestjs/common';
import { apm } from 'src/core/apm';
export class WhatsappService {
async sendMessage(data) {
@ -25,8 +26,14 @@ export class WhatsappService {
data: data,
};
const response = await axios(config);
return response.data;
try {
const response = await axios(config);
return response.data;
} catch (error) {
Logger.error(error);
apm?.captureError(error);
return null;
}
}
async queueRegister(data: WhatsappQueue) {
@ -91,8 +98,11 @@ export class WhatsappService {
},
};
await this.sendMessage(payload);
Logger.log(`Notification register for ${data.code} send to ${data.phone}`);
const response = await this.sendMessage(payload);
if (response)
Logger.log(
`Notification register for ${data.code} send to ${data.phone}`,
);
}
async queueProcess(data: WhatsappQueue) {
@ -152,7 +162,8 @@ export class WhatsappService {
},
};
await this.sendMessage(payload);
Logger.log(`Notification process for ${data.code} send to ${data.phone}`);
const response = await this.sendMessage(payload);
if (response)
Logger.log(`Notification process for ${data.code} send to ${data.phone}`);
}
}