"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var fetch_retry_exports = {};
__export(fetch_retry_exports, {
  fetchRetry: () => fetchRetry
});
module.exports = __toCommonJS(fetch_retry_exports);
const fetchRetry = async ({
  url,
  options,
  retries
}) => {
  try {
    const res = await fetch(url, options);
    if (res.ok) {
      const data = await res.text();
      return data;
    }
    if (retries === 1)
      throw new Error(`status: ${res.status}, ${res.statusText}`);
    return await fetchRetry({ url, options, retries: retries - 1 });
  } catch (err) {
    if (retries === 1) throw err;
    return await fetchRetry({ url, options, retries: retries - 1 });
  }
};
