relocate redirection loop error throw

This commit is contained in:
Evert Prants 2021-01-18 15:21:53 +02:00
parent b1d4978024
commit 3b04a27f0e
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 5 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@squeebot/core", "name": "@squeebot/core",
"version": "3.1.0", "version": "3.1.1",
"description": "Squeebot v3 core for the execution environment", "description": "Squeebot v3 core for the execution environment",
"main": "lib/index.js", "main": "lib/index.js",
"module": "lib/", "module": "lib/",

View File

@ -10,9 +10,6 @@ export function httpGET(
restrictToText = true, restrictToText = true,
saveTo?: string, saveTo?: string,
lback?: number): Promise<any> { lback?: number): Promise<any> {
if (lback && lback >= 4) {
throw new Error('infinite loop!');
}
const parsed = url.parse(link); const parsed = url.parse(link);
const opts = { const opts = {
@ -35,6 +32,10 @@ export function httpGET(
const httpModule = parsed.protocol === 'https:' ? https : http; const httpModule = parsed.protocol === 'https:' ? https : http;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (lback && lback >= 5) {
return reject(new Error('infinite loop!'));
}
const req = httpModule.get(opts, (res) => { const req = httpModule.get(opts, (res) => {
if (res.statusCode === 302 || res.statusCode === 301) { if (res.statusCode === 302 || res.statusCode === 301) {
if (!lback) { if (!lback) {