Improve handling of fetch errors
This commit is contained in:
parent
fa603ef5f2
commit
1fb1d20bee
1 changed files with 4 additions and 0 deletions
|
@ -153,6 +153,7 @@ async function fetchHtmlPage(url: string): Promise<string> {
|
||||||
const response = await fetch(url)
|
const response = await fetch(url)
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
if (retriesCount === 0) {
|
if (retriesCount === 0) {
|
||||||
|
console.warn(`Error while retrieving HTML page at ${url}`)
|
||||||
console.warn(response.status, response.statusText)
|
console.warn(response.status, response.statusText)
|
||||||
console.warn(JSON.stringify(response.headers, null, 2))
|
console.warn(JSON.stringify(response.headers, null, 2))
|
||||||
console.warn(await response.text())
|
console.warn(await response.text())
|
||||||
|
@ -160,6 +161,7 @@ async function fetchHtmlPage(url: string): Promise<string> {
|
||||||
if (retriesCount < 10) {
|
if (retriesCount < 10) {
|
||||||
await sleep(30)
|
await sleep(30)
|
||||||
console.info("Retrying…")
|
console.info("Retrying…")
|
||||||
|
continue
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Retrieval of HTML page at <${url}> failed`)
|
throw new Error(`Retrieval of HTML page at <${url}> failed`)
|
||||||
}
|
}
|
||||||
|
@ -167,6 +169,7 @@ async function fetchHtmlPage(url: string): Promise<string> {
|
||||||
const html = await response.text()
|
const html = await response.text()
|
||||||
if (html.includes("Request unsuccessful. Incapsula incident ID:")) {
|
if (html.includes("Request unsuccessful. Incapsula incident ID:")) {
|
||||||
if (retriesCount === 0) {
|
if (retriesCount === 0) {
|
||||||
|
console.warn(`Error while retrieving HTML page at ${url}`)
|
||||||
console.warn(response.status, response.statusText)
|
console.warn(response.status, response.statusText)
|
||||||
console.warn(JSON.stringify(response.headers, null, 2))
|
console.warn(JSON.stringify(response.headers, null, 2))
|
||||||
console.warn(html)
|
console.warn(html)
|
||||||
|
@ -174,6 +177,7 @@ async function fetchHtmlPage(url: string): Promise<string> {
|
||||||
if (retriesCount < 10) {
|
if (retriesCount < 10) {
|
||||||
await sleep(30)
|
await sleep(30)
|
||||||
console.info("Retrying…")
|
console.info("Retrying…")
|
||||||
|
continue
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Retrieval of HTML page at <${url}> failed`)
|
throw new Error(`Retrieval of HTML page at <${url}> failed`)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue