mirror of https://github.com/coder/code-server.git
Fix crash when unable to request an update
This commit is contained in:
parent
27320465b7
commit
0a5687bacf
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue