chore: print response body when browser download failed (#15101)

This commit is contained in:
Max Schmitt 2022-06-28 18:19:31 +02:00 committed by GitHub
parent bcb013d240
commit aa1e736f3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,10 +48,17 @@ function downloadFile(url: string, destinationPath: string, options: DownloadFil
}, response => {
log(`-- response status code: ${response.statusCode}`);
if (response.statusCode !== 200) {
const error = new Error(`Download failed: server returned code ${response.statusCode}. URL: ${url}`);
// consume response data to free up memory
response.resume();
fulfill({ error });
let content = '';
const handleError = () => {
const error = new Error(`Download failed: server returned code ${response.statusCode} body '${content}'. URL: ${url}`);
// consume response data to free up memory
response.resume();
fulfill({ error });
};
response
.on('data', chunk => content += chunk)
.on('end', handleError)
.on('error', handleError);
return;
}
const file = fs.createWriteStream(destinationPath);