diff options
author | Veetaha <[email protected]> | 2020-02-13 22:31:23 +0000 |
---|---|---|
committer | Veetaha <[email protected]> | 2020-02-13 22:33:12 +0000 |
commit | 574dc11a2fed943bc40e338b22c5b12bef66e768 (patch) | |
tree | 6bbf4cd86ac33f9ac1481d957ecab06bae1afa00 /editors/code/src | |
parent | da6ae3b6e0700acf80eeb27b513abdd381c50916 (diff) |
vscode: removed nested errors as per matklad
Diffstat (limited to 'editors/code/src')
-rw-r--r-- | editors/code/src/installation/download_file.ts | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/editors/code/src/installation/download_file.ts b/editors/code/src/installation/download_file.ts index 591de0d31..d154f4816 100644 --- a/editors/code/src/installation/download_file.ts +++ b/editors/code/src/installation/download_file.ts | |||
@@ -3,7 +3,6 @@ import * as fs from "fs"; | |||
3 | import * as stream from "stream"; | 3 | import * as stream from "stream"; |
4 | import * as util from "util"; | 4 | import * as util from "util"; |
5 | import { strict as assert } from "assert"; | 5 | import { strict as assert } from "assert"; |
6 | import { NestedError } from "ts-nested-error"; | ||
7 | 6 | ||
8 | const pipeline = util.promisify(stream.pipeline); | 7 | const pipeline = util.promisify(stream.pipeline); |
9 | 8 | ||
@@ -19,13 +18,13 @@ export async function downloadFile( | |||
19 | destFilePermissions: number, | 18 | destFilePermissions: number, |
20 | onProgress: (readBytes: number, totalBytes: number) => void | 19 | onProgress: (readBytes: number, totalBytes: number) => void |
21 | ): Promise<void> { | 20 | ): Promise<void> { |
22 | const res = await fetch(url).catch(NestedError.rethrow("Failed at initial fetch")); | 21 | const res = await fetch(url); |
23 | 22 | ||
24 | if (!res.ok) { | 23 | if (!res.ok) { |
25 | console.log("Error", res.status, "while downloading file from", url); | 24 | console.log("Error", res.status, "while downloading file from", url); |
26 | console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 }); | 25 | console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 }); |
27 | 26 | ||
28 | throw new NestedError(`Got response ${res.status}`); | 27 | throw new Error(`Got response ${res.status} when trying to download a file.`); |
29 | } | 28 | } |
30 | 29 | ||
31 | const totalBytes = Number(res.headers.get('content-length')); | 30 | const totalBytes = Number(res.headers.get('content-length')); |
@@ -41,7 +40,7 @@ export async function downloadFile( | |||
41 | 40 | ||
42 | const destFileStream = fs.createWriteStream(destFilePath, { mode: destFilePermissions }); | 41 | const destFileStream = fs.createWriteStream(destFilePath, { mode: destFilePermissions }); |
43 | 42 | ||
44 | await pipeline(res.body, destFileStream).catch(NestedError.rethrow("Piping file error")); | 43 | await pipeline(res.body, destFileStream); |
45 | return new Promise<void>(resolve => { | 44 | return new Promise<void>(resolve => { |
46 | destFileStream.on("close", resolve); | 45 | destFileStream.on("close", resolve); |
47 | destFileStream.destroy(); | 46 | destFileStream.destroy(); |