mirror of
https://github.com/coder/code-server.git
synced 2024-12-25 18:52:34 +03:00
Simplify update request
This commit is contained in:
parent
3a074fd844
commit
f4e5855318
@ -105,24 +105,23 @@ export class UpdateProvider {
|
|||||||
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
|
||||||
const client = 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 < 200 || response.statusCode >= 400) {
|
||||||
response.statusCode &&
|
return reject(new Error(`${uri}: ${response.statusCode || "500"}`))
|
||||||
response.statusCode >= 300 &&
|
}
|
||||||
response.statusCode < 400 &&
|
|
||||||
response.headers.location
|
if (response.statusCode >= 300) {
|
||||||
) {
|
|
||||||
++redirects
|
++redirects
|
||||||
if (redirects > maxRedirects) {
|
if (redirects > maxRedirects) {
|
||||||
|
response.destroy()
|
||||||
return reject(new Error("reached max redirects"))
|
return reject(new Error("reached max redirects"))
|
||||||
}
|
}
|
||||||
|
if (!response.headers.location) {
|
||||||
|
return reject(new Error("received redirect with no location header"))
|
||||||
|
}
|
||||||
response.destroy()
|
response.destroy()
|
||||||
return request(url.resolve(uri, response.headers.location))
|
return request(url.resolve(uri, response.headers.location))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response.statusCode || response.statusCode < 200 || response.statusCode >= 400) {
|
|
||||||
return reject(new Error(`${uri}: ${response.statusCode || "500"}`))
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve(response)
|
resolve(response)
|
||||||
})
|
})
|
||||||
client.on("error", reject)
|
client.on("error", reject)
|
||||||
|
Loading…
Reference in New Issue
Block a user