@qctrl/website-validator
Version:
Q-CTRL Website Validator provides a set of utility tools that validate HTML pages and hyperlinks.
36 lines (35 loc) • 1.44 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import delay from "./delay.js";
/**
* Fetch page
*
* @param url - Url to fetch
* @param attempts - Number of attempts to fetch url
*
* @returns Fetch response object
*/
export default function request(url_1) {
return __awaiter(this, arguments, void 0, function* (url, attempts = 1) {
try {
return yield fetch(url, {
redirect: "follow",
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36",
},
});
}
catch (_a) {
yield delay(5000);
const result = yield request(url, attempts + 1);
return result;
}
});
}