diff --git a/server/src/controllers/analytics_controller.ts b/server/src/controllers/analytics_controller.ts index 3cf6f28..7509170 100644 --- a/server/src/controllers/analytics_controller.ts +++ b/server/src/controllers/analytics_controller.ts @@ -264,7 +264,11 @@ async function processDetectionResult(analyticUnitId: AnalyticUnit.AnalyticUnitI const analyticUnit = await AnalyticUnit.findById(analyticUnitId); if(analyticUnit.alert) { if(!_.isEmpty(segments)) { - sendWebhook(analyticUnit.name, _.last(segments)); + try { + sendWebhook(analyticUnit.name, _.last(segments)); + } catch(err) { + console.error(`Error while sending webhook: ${err.message}`); + } } } return { diff --git a/server/src/services/notification_service.ts b/server/src/services/notification_service.ts index dc94061..fd6bc1b 100644 --- a/server/src/services/notification_service.ts +++ b/server/src/services/notification_service.ts @@ -7,10 +7,6 @@ import * as querystring from 'querystring'; // TODO: send webhook with payload without dep to AnalyticUnit export async function sendWebhook(analyticUnitName: string, segment: Segment) { - if(HASTIC_WEBHOOK_URL === null) { - throw new Error(`Can't send alert, HASTIC_WEBHOOK_URL is undefined`); - } - const alert = { analyticUnitName, from: segment.from, @@ -19,6 +15,10 @@ export async function sendWebhook(analyticUnitName: string, segment: Segment) { console.log(`Sending alert: ${JSON.stringify(alert)}`); + if(HASTIC_WEBHOOK_URL === null) { + throw new Error(`Can't send alert, HASTIC_WEBHOOK_URL is undefined`); + } + let payload; if(HASTIC_WEBHOOK_TYPE === 'application/json') { payload = JSON.stringify(alert);