1
0
mirror of https://github.com/louislam/uptime-kuma.git synced 2024-12-14 10:23:16 +02:00
uptime-kuma/server/notification-providers/notification-provider.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-09-07 16:42:46 +02:00
class NotificationProvider {
/**
* Notification Provider Name
* @type {string}
2021-09-07 16:42:46 +02:00
*/
name = undefined;
/**
* Send a notification
* @param {BeanModel} notification Notification to send
* @param {string} msg General Message
* @param {?object} monitorJSON Monitor details (For Up/Down only)
* @param {?object} heartbeatJSON Heartbeat details (For Up/Down only)
2021-09-07 16:42:46 +02:00
* @returns {Promise<string>} Return Successful Message
* @throws Error with fail msg
2021-09-07 16:42:46 +02:00
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
throw new Error("Have to override Notification.send(...)");
}
/**
* Throws an error
* @param {any} error The error to throw
* @returns {void}
* @throws {any} The error specified
*/
2021-09-07 16:42:46 +02:00
throwGeneralAxiosError(error) {
let msg = "Error: " + error + " ";
if (error.response && error.response.data) {
if (typeof error.response.data === "string") {
msg += error.response.data;
} else {
2022-04-13 18:30:32 +02:00
msg += JSON.stringify(error.response.data);
2021-09-07 16:42:46 +02:00
}
}
2022-04-13 18:30:32 +02:00
throw new Error(msg);
2021-09-07 16:42:46 +02:00
}
}
module.exports = NotificationProvider;