diff --git a/src/utils.ts b/src/utils.ts index 5a31f2eb..6d1b677f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -44,7 +44,16 @@ export function downloadToFile( ): Promise { return new Promise(async (resolve, reject) => { try { - const response = await fetch(url, { timeout: 2 * 60 * 1000 }); // Timeout in 2 minutes. + const response = await fetch(url, { + redirect: 'follow', + follow: 5, + timeout: 2 * 60 * 1000, // Timeout in 2 minutes. + }); + if (response.status < 200 || response.status > 299) { + throw new Error( + `Download failed with response status code ${response.status}` + ); + } const writer = createWriteStream(file, { mode }); response.body.pipe(writer); writer.on('close', () => {