chore(install): Improve ECONNRESET handling in downloadFile (#28344)

See
https://github.com/microsoft/playwright/issues/28329#issuecomment-1826753106
for context
This commit is contained in:
Alexander Kachkaev 2023-11-27 20:44:24 +00:00 committed by GitHub
parent dc8ecc3ca4
commit 41728e7098
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -85,12 +85,15 @@ function downloadFile(options: DownloadParams): Promise<void> {
file.on('error', error => promise.reject(error));
response.pipe(file);
response.on('data', onData);
response.on('close', () => {
if (response.complete)
return;
response.on('error', (error: any) => {
file.close();
log(`-- download failed, server closed connection`);
promise.reject(new Error(`Download failed: server closed connection. URL: ${options.url}`));
if (error?.code === 'ECONNRESET') {
log(`-- download failed, server closed connection`);
promise.reject(new Error(`Download failed: server closed connection. URL: ${options.url}`));
} else {
log(`-- download failed, unexpected error`);
promise.reject(new Error(`Download failed: ${error?.message ?? error}. URL: ${options.url}`));
}
});
}, (error: any) => promise.reject(error));
return promise;