Repository: louislam/uptime-kuma
File: server/notification-providers/pagertree.js (JavaScript)

Code before:
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { UP, DOWN, getMonitorRelativeURL } = require("../../src/util");
const { setting } = require("../util-server");
let successMessage = "Sent Successfully.";

class PagerTree extends NotificationProvider {
    name = "PagerTree";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        try {
            if (heartbeatJSON == null) {
                const title = "[Test] Uptime Kuma Alert";
                return this.postNotification(notification, title, monitorJSON, heartbeatJSON);
            }

            if (heartbeatJSON.status === UP && notification.pagertreeAutoResolve === "resolve") {
                return this.postNotification(notification, null, monitorJSON, heartbeatJSON, notification.pagertreeAutoResolve);
            }

            if (heartbeatJSON.status === DOWN) {
                const title = `Uptime Kuma Monitor "${monitorJSON.name}" is DOWN`;
                return this.postNotification(notification, title, monitorJSON, heartbeatJSON);
            }
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }

    /**
     * Check if result is successful, result code should be in range 2xx
     * @param {Object} result Axios response object
     * @throws {Error} The status code is not in range 2xx
     */
    checkResult(result) {
        if (result.status == null) {
            throw new Error("PagerTree notification failed with invalid response!");
        }
        if (result.status < 200 || result.status >= 300) {

Review comment (suggestion):
If `heartbeatJSON == null`, it is not for test. It is for general messages. You should send `msg`.

Code after:
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { UP, DOWN, getMonitorRelativeURL } = require("../../src/util");
const { setting } = require("../util-server");
let successMessage = "Sent Successfully.";

class PagerTree extends NotificationProvider {
    name = "PagerTree";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        try {
            if (heartbeatJSON == null) {
                // general messages
                return this.postNotification(notification, msg, monitorJSON, heartbeatJSON);
            }

            if (heartbeatJSON.status === UP && notification.pagertreeAutoResolve === "resolve") {
                return this.postNotification(notification, null, monitorJSON, heartbeatJSON, notification.pagertreeAutoResolve);
            }

            if (heartbeatJSON.status === DOWN) {
                const title = `Uptime Kuma Monitor "${monitorJSON.name}" is DOWN`;
                return this.postNotification(notification, title, monitorJSON, heartbeatJSON);
            }
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }

    /**
     * Check if result is successful, result code should be in range 2xx
     * @param {Object} result Axios response object
     * @throws {Error} The status code is not in range 2xx
     */
    checkResult(result) {
        if (result.status == null) {
            throw new Error("PagerTree notification failed with invalid response!");
        }
        if (result.status < 200 || result.status >= 300) {