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

Code before:
    /**
     * Check if result is successful
     * @param {object} result Axios response object
     * @returns {void}
     * @throws {Error} The status code is not in range 2xx
     */
    checkResult(result) {
        if (result.status == null) {
            throw new Error("Bark notification failed with invalid response!");
        }
        if (result.status < 200 || result.status >= 300) {
            throw new Error("Bark notification failed with status code " + result.status);
        }
    }

    /**
     * Send the message
     * @param {BeanModel} notification Notification to send
     * @param {string} title Message title
     * @param {string} subtitle Message
     * @param {string} endpoint Endpoint to send request to
     * @returns {string} Success message
     */
    async postNotification(notification, title, subtitle, endpoint) {
        let result;
        if (notification.apiVersion == "v1") {
            // url encode title and subtitle
            title = encodeURIComponent(title);
            subtitle = encodeURIComponent(subtitle);
            let postUrl = endpoint + "/" + title + "/" + subtitle;
            postUrl = this.appendAdditionalParameters(notification, postUrl);
            result = await axios.get(postUrl);
        } else {
            result = await axios.post(`${endpoint}/push`, {
                title,
                body: subtitle,
                icon: barkNotificationAvatar,
                sound: notification.barkSound || "telegraph", // default sound is telegraph
                group: notification.barkGroup || "UptimeKuma", // default group is UptimeKuma
            });
        }
        this.checkResult(result);
        if (result.statusText != null) {
            return "Bark notification succeed: " + result.statusText;
        }
        // because returned in range 200 ..< 300
        return successMessage;
    }
}

module.exports = Bark;

Review comment (suggestion):
```suggestion
        if (notification.apiVersion === "v1" || notification.apiVersion == null) {
```

Code after:
    /**
     * Check if result is successful
     * @param {object} result Axios response object
     * @returns {void}
     * @throws {Error} The status code is not in range 2xx
     */
    checkResult(result) {
        if (result.status == null) {
            throw new Error("Bark notification failed with invalid response!");
        }
        if (result.status < 200 || result.status >= 300) {
            throw new Error("Bark notification failed with status code " + result.status);
        }
    }

    /**
     * Send the message
     * @param {BeanModel} notification Notification to send
     * @param {string} title Message title
     * @param {string} subtitle Message
     * @param {string} endpoint Endpoint to send request to
     * @returns {string} Success message
     */
    async postNotification(notification, title, subtitle, endpoint) {
        let result;
        if (notification.apiVersion === "v1" || notification.apiVersion == null) {
            // url encode title and subtitle
            title = encodeURIComponent(title);
            subtitle = encodeURIComponent(subtitle);
            let postUrl = endpoint + "/" + title + "/" + subtitle;
            postUrl = this.appendAdditionalParameters(notification, postUrl);
            result = await axios.get(postUrl);
        } else {
            result = await axios.post(`${endpoint}/push`, {
                title,
                body: subtitle,
                icon: barkNotificationAvatar,
                sound: notification.barkSound || "telegraph", // default sound is telegraph
                group: notification.barkGroup || "UptimeKuma", // default group is UptimeKuma
            });
        }
        this.checkResult(result);
        if (result.statusText != null) {
            return "Bark notification succeed: " + result.statusText;
        }
        // because returned in range 200 ..< 300
        return successMessage;
    }
}

module.exports = Bark;