From 0a5687bacf192afad07e43fe5d4555cf766af8a4 Mon Sep 17 00:00:00 2001 From: Asher Date: Wed, 25 Mar 2020 15:00:35 -0500 Subject: [PATCH] Fix crash when unable to request an update --- src/node/app/update.ts | 3 ++- test/update.test.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/node/app/update.ts b/src/node/app/update.ts index 3f722d515..9ae64e5ce 100644 --- a/src/node/app/update.ts +++ b/src/node/app/update.ts @@ -341,7 +341,7 @@ export class UpdateHttpProvider extends HttpProvider { const request = (uri: string): void => { logger.debug("Making request", field("uri", uri)) const httpx = uri.startsWith("https") ? https : http - httpx.get(uri, { headers: { "User-Agent": "code-server" } }, (response) => { + const client = httpx.get(uri, { headers: { "User-Agent": "code-server" } }, (response) => { if ( response.statusCode && response.statusCode >= 300 && @@ -362,6 +362,7 @@ export class UpdateHttpProvider extends HttpProvider { resolve(response) }) + client.on("error", reject) } request(uri) }) diff --git a/test/update.test.ts b/test/update.test.ts index 779dba1a5..da3634e92 100644 --- a/test/update.test.ts +++ b/test/update.test.ts @@ -222,4 +222,23 @@ describe("update", () => { const archiveName = await p.getReleaseName(update) assert.deepEqual(spy, ["/latest", `/download/${version}/${archiveName}`, `/download/${version}/${archiveName}`]) }) + + it("should not reject if unable to fetch", async () => { + const options = { + auth: AuthType.None, + base: "/update", + commit: "test", + } + let provider = new UpdateHttpProvider(options, true, "invalid", "invalid", settings) + await assert.doesNotReject(() => provider.getUpdate(true)) + + provider = new UpdateHttpProvider( + options, + true, + "http://probably.invalid.dev.localhost/latest", + "http://probably.invalid.dev.localhost/download", + settings, + ) + await assert.doesNotReject(() => provider.getUpdate(true)) + }) })