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

Code before:
                    url: msg,
                };
                return this.postNotification(notification, title, msg, monitor);
            }

            if (heartbeatJSON.status === UP) {
                const title = "Uptime Kuma Monitor ✅ Up";

                return this.postNotification(notification, title, heartbeatJSON.msg, monitorJSON, "Ok");
            }

            if (heartbeatJSON.status === DOWN) {
                const title = "Uptime Kuma Monitor 🔴 Down";
                return this.postNotification(notification, title, heartbeatJSON.msg, monitorJSON, notification.flashdutySeverity);
            }
        } 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("FlashDuty notification failed with invalid response!");
        }
        if (result.status < 200 || result.status >= 300) {
            throw new Error("FlashDuty notification failed with status code " + result.status);
        }
    }

    /**
     * Send the message
     * @param {BeanModel} notification Message title
     * @param {string} title Message
     * @param {string} body Message
     * @param {Object} monitorInfo Monitor details
     * @param {string} eventStatus Monitor status (Info, Warning, Critical, Ok)
     * @returns {string}
     */
    async postNotification(notification, title, body, monitorInfo, eventStatus) {
        const genMonitorUrl = (monitorInfo) => {
            let monitorUrl;
            if (monitorInfo.type === "port") {
                monitorUrl = monitorInfo.hostname;
                if (monitorInfo.port) {
                    monitorUrl += ":" + monitorInfo.port;
                }

Review comment (suggestion):
I don't think exctracting this part of the results check from `postNotification` increases readability, as this essentially splits the code which checks the result into two parts
=> please inline this function

Code after:
                    url: msg,
                    name: "https://flashcat.cloud"
                };
                return this.postNotification(notification, title, msg, monitor);
            }

            if (heartbeatJSON.status === UP) {
                const title = "Uptime Kuma Monitor ✅ Up";

                return this.postNotification(notification, title, heartbeatJSON.msg, monitorJSON, "Ok");
            }

            if (heartbeatJSON.status === DOWN) {
                const title = "Uptime Kuma Monitor 🔴 Down";
                return this.postNotification(notification, title, heartbeatJSON.msg, monitorJSON, notification.flashdutySeverity);
            }
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
    /**
     * Generate a monitor url from the monitors infomation
     * @param {Object} monitorInfo Monitor details
     * @returns {string|undefined}
     */

    genMonitorUrl(monitorInfo) {
        if (monitorInfo.type === "port" && monitorInfo.port) {
            return monitorInfo.hostname + ":" + monitorInfo.port;
        }
        if (monitorInfo.hostname != null) {
            return monitorInfo.hostname;
        }
        return monitorInfo.url;
    }

    /**
     * Send the message
     * @param {BeanModel} notification Message title
     * @param {string} title Message
     * @param {string} body Message
     * @param {Object} monitorInfo Monitor details
     * @param {string} eventStatus Monitor status (Info, Warning, Critical, Ok)
     * @returns {string}
     */
    async postNotification(notification, title, body, monitorInfo, eventStatus) {
        const options = {
            method: "POST",
            url: "https://api.flashcat.cloud/event/push/alert/standard?integration_key=" + notification.flashdutyIntegrationKey,
            headers: { "Content-Type": "application/json" },
            data: {