Retry when page contains an error message

This commit is contained in:
Emmanuel 2024-05-20 14:27:05 +02:00
parent c1a4827545
commit fa603ef5f2

View file

@ -164,7 +164,21 @@ async function fetchHtmlPage(url: string): Promise<string> {
throw new Error(`Retrieval of HTML page at <${url}> failed`)
}
}
return await response.text()
const html = await response.text()
if (html.includes("Request unsuccessful. Incapsula incident ID:")) {
if (retriesCount === 0) {
console.warn(response.status, response.statusText)
console.warn(JSON.stringify(response.headers, null, 2))
console.warn(html)
}
if (retriesCount < 10) {
await sleep(30)
console.info("Retrying…")
} else {
throw new Error(`Retrieval of HTML page at <${url}> failed`)
}
}
return html
}
}