Skip to content

Commit

Permalink
fix(util): follow redirects in fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
paambaati committed Apr 24, 2023
1 parent 9787ba6 commit a258bd9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ export function downloadToFile(
): Promise<void> {
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', () => {
Expand Down

0 comments on commit a258bd9

Please sign in to comment.