"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkWebUrl = void 0;
const util_1 = require("../../util");
const index_1 = require("./index");
require("isomorphic-fetch");
/**
 * This is a helper function to check if a web url is reachable.
 * @param url
 * @param createSuccess
 * @returns
 */
const checkWebUrl = async (effects, url, { timeout = 1000, successMessage = `Reached ${url}`, errorMessage = `Error while fetching URL: ${url}`, } = {}) => {
    return Promise.race([fetch(url), (0, index_1.timeoutPromise)(timeout)])
        .then((x) => ({
        result: 'success',
        message: successMessage,
    }))
        .catch((e) => {
        console.warn(`Error while fetching URL: ${url}`);
        console.error(JSON.stringify(e));
        console.error((0, util_1.asError)(e));
        return { result: 'failure', message: errorMessage };
    });
};
exports.checkWebUrl = checkWebUrl;
//# sourceMappingURL=checkWebUrl.js.map