Browse Source

Exception if hastic webhook url is undefined #593 (#718)

pull/1/head
Evgeny Smyshlyaev 5 years ago committed by GitHub
parent
commit
21d575651a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      server/src/services/alert_service.ts
  2. 3
      server/src/services/notification_service.ts

14
server/src/services/alert_service.ts

@ -19,7 +19,11 @@ export class Alert {
protected async send(segment) { protected async send(segment) {
const notification = await this.makeNotification(segment); const notification = await this.makeNotification(segment);
sendNotification(notification); try {
await sendNotification(notification);
} catch(error) {
console.error(`can't send notification ${error}`);
};
} }
protected async makeNotification(segment: Segment): Promise<Notification> { protected async makeNotification(segment: Segment): Promise<Notification> {
@ -187,7 +191,7 @@ export class AlertService {
this._alerts[id].receive(segment); this._alerts[id].receive(segment);
}; };
public sendMsg(message: string, type: WebhookType, optionalInfo = {}) { public async sendMsg(message: string, type: WebhookType, optionalInfo = {}) {
const now = Date.now(); const now = Date.now();
const infoAlert: InfoMeta = { const infoAlert: InfoMeta = {
params: optionalInfo, params: optionalInfo,
@ -195,7 +199,11 @@ export class AlertService {
from: now, from: now,
to: now to: now
} }
sendNotification({ message, meta: infoAlert }); try {
await sendNotification({ message, meta: infoAlert })
} catch(error) {
console.error(`can't send notification ${error}`);
};
} }
public sendGrafanaAvailableWebhook() { public sendGrafanaAvailableWebhook() {

3
server/src/services/notification_service.ts

@ -43,7 +43,8 @@ export declare type Notification = {
export async function sendNotification(notification: Notification) { export async function sendNotification(notification: Notification) {
if(HASTIC_WEBHOOK_URL === null) { if(HASTIC_WEBHOOK_URL === null) {
throw new Error(`Can't send notification, HASTIC_WEBHOOK_URL is undefined`); console.log(`HASTIC_WEBHOOK_URL is not set, skip sending notification: ${notification.message}`);
return;
} }
notification.message += `\nInstance: ${HASTIC_INSTANCE_NAME}`; notification.message += `\nInstance: ${HASTIC_INSTANCE_NAME}`;

Loading…
Cancel
Save