mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-15 14:11:50 +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 => {
|
}, 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);
|
||||||
|
Loading…
Reference in New Issue
Block a user