aboutsummaryrefslogtreecommitdiff
path: root/editors/code
diff options
context:
space:
mode:
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 b51602ef9..9d37eaa0e 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);