mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 21:53:35 +03:00
chore: print response body when browser download failed (#15101)
This commit is contained in:
parent
bcb013d240
commit
aa1e736f3f
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user