Skip to content

Commit

Permalink
Handle request timeout events
Browse files Browse the repository at this point in the history
  • Loading branch information
onyb committed Jan 10, 2024
1 parent 899150e commit b0f60f1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion scripts/util.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ const modifySvgFile = (file) => {
async function download(url, directory, filename, ext) {
console.log(`Download: ${url}`)
return new Promise((resolve, reject) => {
const request = https.get(url, { timeout: 2000 }, (response) => {
const request = https.get(url, { timeout: 3000 }, (response) => {
if (response.statusCode < 200 || response.statusCode >= 300) {
console.error(`Download failed: ${url}`)
reject()
Expand All @@ -284,6 +284,12 @@ async function download(url, directory, filename, ext) {
console.error(`Download failed: ${url}`)
reject(err)
})

request.on("timeout", () => {
request.destroy()
console.error(`Download timed out: ${url}`)
reject()
})
})
}

Expand Down

0 comments on commit b0f60f1

Please sign in to comment.