diff --git a/editors/code/src/installation/download_file.ts b/editors/code/src/installation/download_file.ts index fe356c39d6d..8a0766c6626 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( destFilePath: fs.PathLike, onProgress: (readBytes: number, totalBytes: number) => void ): Promise { - const response = await fetch(url); + const res = await fetch(url); - const totalBytes = Number(response.headers.get('content-length')); + if (!res.ok) { + console.log("Error", res.status, "while downloading file from", url); + console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 }); + + throw new Error(`Got response ${res.status} when trying to download a file`); + } + + const totalBytes = Number(res.headers.get('content-length')); assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol"); let readBytes = 0; console.log("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath); - return new Promise((resolve, reject) => response.body + return new Promise((resolve, reject) => res.body .on("data", (chunk: Buffer) => { readBytes += chunk.length; onProgress(readBytes, totalBytes);