Archived
1
0

Fix crash when unable to request an update

This commit is contained in:
Asher 2020-03-25 15:00:35 -05:00
parent 27320465b7
commit 0a5687bacf
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
2 changed files with 21 additions and 1 deletions

View File

@ -341,7 +341,7 @@ export class UpdateHttpProvider extends HttpProvider {
const request = (uri: string): void => { const request = (uri: string): void => {
logger.debug("Making request", field("uri", uri)) logger.debug("Making request", field("uri", uri))
const httpx = uri.startsWith("https") ? https : http 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 ( if (
response.statusCode && response.statusCode &&
response.statusCode >= 300 && response.statusCode >= 300 &&
@ -362,6 +362,7 @@ export class UpdateHttpProvider extends HttpProvider {
resolve(response) resolve(response)
}) })
client.on("error", reject)
} }
request(uri) request(uri)
}) })

View File

@ -222,4 +222,23 @@ describe("update", () => {
const archiveName = await p.getReleaseName(update) const archiveName = await p.getReleaseName(update)
assert.deepEqual(spy, ["/latest", `/download/${version}/${archiveName}`, `/download/${version}/${archiveName}`]) 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))
})
}) })