aboutsummaryrefslogtreecommitdiff
path: root/editors/code
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-11 09:25:31 +0000
committerGitHub <[email protected]>2020-02-11 09:25:31 +0000
commit98aa709fa75bf53f8b96e26c6b8e7ed29a086ebf (patch)
tree4b8ac5163822cd006b1dfe83ca406dc1b2b39f6e /editors/code
parentaf9a9abbd8011d751e5d37f68c486336cb41ac65 (diff)
parentf2c66605c2482e9e6b611b6e062ea475a42a620f (diff)
Merge #3100
3100: vscode: add error handling to downloadFile() r=matklad a=Veetaha Inspired by #3094. Co-authored-by: Veetaha <[email protected]>
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/src/installation/download_file.ts13
1 files changed, 10 insertions, 3 deletions
diff --git a/editors/code/src/installation/download_file.ts b/editors/code/src/installation/download_file.ts
index fe356c39d..8a0766c66 100644
--- a/editors/code/src/installation/download_file.ts
+++ b/editors/code/src/installation/download_file.ts
@@ -13,16 +13,23 @@ export async function downloadFile(
13 destFilePath: fs.PathLike, 13 destFilePath: fs.PathLike,
14 onProgress: (readBytes: number, totalBytes: number) => void 14 onProgress: (readBytes: number, totalBytes: number) => void
15): Promise<void> { 15): Promise<void> {
16 const response = await fetch(url); 16 const res = await fetch(url);
17 17
18 const totalBytes = Number(response.headers.get('content-length')); 18 if (!res.ok) {
19 console.log("Error", res.status, "while downloading file from", url);
20 console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 });
21
22 throw new Error(`Got response ${res.status} when trying to download a file`);
23 }
24
25 const totalBytes = Number(res.headers.get('content-length'));
19 assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol"); 26 assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol");
20 27
21 let readBytes = 0; 28 let readBytes = 0;
22 29
23 console.log("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath); 30 console.log("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath);
24 31
25 return new Promise<void>((resolve, reject) => response.body 32 return new Promise<void>((resolve, reject) => res.body
26 .on("data", (chunk: Buffer) => { 33 .on("data", (chunk: Buffer) => {
27 readBytes += chunk.length; 34 readBytes += chunk.length;
28 onProgress(readBytes, totalBytes); 35 onProgress(readBytes, totalBytes);