Skip to content

Commit 0a5687b

Browse files
committed
Fix crash when unable to request an update
1 parent 2732046 commit 0a5687b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/node/app/update.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export class UpdateHttpProvider extends HttpProvider {
341341
const request = (uri: string): void => {
342342
logger.debug("Making request", field("uri", uri))
343343
const httpx = uri.startsWith("https") ? https : http
344-
httpx.get(uri, { headers: { "User-Agent": "code-server" } }, (response) => {
344+
const client = httpx.get(uri, { headers: { "User-Agent": "code-server" } }, (response) => {
345345
if (
346346
response.statusCode &&
347347
response.statusCode >= 300 &&
@@ -362,6 +362,7 @@ export class UpdateHttpProvider extends HttpProvider {
362362

363363
resolve(response)
364364
})
365+
client.on("error", reject)
365366
}
366367
request(uri)
367368
})

test/update.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,23 @@ describe("update", () => {
222222
const archiveName = await p.getReleaseName(update)
223223
assert.deepEqual(spy, ["/latest", `/download/${version}/${archiveName}`, `/download/${version}/${archiveName}`])
224224
})
225+
226+
it("should not reject if unable to fetch", async () => {
227+
const options = {
228+
auth: AuthType.None,
229+
base: "/update",
230+
commit: "test",
231+
}
232+
let provider = new UpdateHttpProvider(options, true, "invalid", "invalid", settings)
233+
await assert.doesNotReject(() => provider.getUpdate(true))
234+
235+
provider = new UpdateHttpProvider(
236+
options,
237+
true,
238+
"http://probably.invalid.dev.localhost/latest",
239+
"http://probably.invalid.dev.localhost/download",
240+
settings,
241+
)
242+
await assert.doesNotReject(() => provider.getUpdate(true))
243+
})
225244
})

0 commit comments

Comments
 (0)