Skip to content

Commit

Permalink
Update webhook error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ericboucher committed Sep 24, 2024
1 parent 8cac404 commit 68f0659
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions apps/backend/src/modules/webhook/webhook.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,27 @@ export class WebhookService {
}

async sendAlerts(disasterType: DisasterType, form: DisasterDtoType) {
if (telegramPcdmChatId === undefined) {
throw new Error('telegramPcdmChatId is not defined');
try {
if (telegramPcdmChatId === undefined) {
throw new Error('telegramPcdmChatId is not defined');
}
if (telegramNcdmChatId === undefined) {
throw new Error('telegramNcdmChatId is not defined');
}

console.log(JSON.stringify(form));

const text = generateTelegramMessage(disasterType, form);

await Promise.all([
this.sendTelegramMessage(telegramPcdmChatId, text),
this.sendTelegramMessage(telegramNcdmChatId, text),
]);

return 'sent';
} catch (error) {
console.error('Error sending alerts:', error);
throw new HttpException('Failed to send alerts', HttpStatus.INTERNAL_SERVER_ERROR);
}
if (telegramNcdmChatId === undefined) {
throw new Error('telegramNcdmChatId is not defined');
}

console.log(form);

const text = generateTelegramMessage(disasterType, form);

await Promise.all([
this.sendTelegramMessage(telegramPcdmChatId, text),
this.sendTelegramMessage(telegramNcdmChatId, text),
]);

return 'sent';
}
}

0 comments on commit 68f0659

Please sign in to comment.