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 => { }, response => {
log(`-- response status code: ${response.statusCode}`); log(`-- response status code: ${response.statusCode}`);
if (response.statusCode !== 200) { if (response.statusCode !== 200) {
const error = new Error(`Download failed: server returned code ${response.statusCode}. URL: ${url}`); let content = '';
// consume response data to free up memory const handleError = () => {
response.resume(); const error = new Error(`Download failed: server returned code ${response.statusCode} body '${content}'. URL: ${url}`);
fulfill({ error }); // consume response data to free up memory
response.resume();
fulfill({ error });
};
response
.on('data', chunk => content += chunk)
.on('end', handleError)
.on('error', handleError);
return; return;
} }
const file = fs.createWriteStream(destinationPath); const file = fs.createWriteStream(destinationPath);