Skip to content

Commit f4e5855

Browse files
committed
Simplify update request
1 parent 3a074fd commit f4e5855

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/node/update.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,23 @@ export class UpdateProvider {
105105
logger.debug("Making request", field("uri", uri))
106106
const httpx = uri.startsWith("https") ? https : http
107107
const client = httpx.get(uri, { headers: { "User-Agent": "code-server" } }, (response) => {
108-
if (
109-
response.statusCode &&
110-
response.statusCode >= 300 &&
111-
response.statusCode < 400 &&
112-
response.headers.location
113-
) {
108+
if (!response.statusCode || response.statusCode < 200 || response.statusCode >= 400) {
109+
return reject(new Error(`${uri}: ${response.statusCode || "500"}`))
110+
}
111+
112+
if (response.statusCode >= 300) {
114113
++redirects
115114
if (redirects > maxRedirects) {
115+
response.destroy()
116116
return reject(new Error("reached max redirects"))
117117
}
118+
if (!response.headers.location) {
119+
return reject(new Error("received redirect with no location header"))
120+
}
118121
response.destroy()
119122
return request(url.resolve(uri, response.headers.location))
120123
}
121124

122-
if (!response.statusCode || response.statusCode < 200 || response.statusCode >= 400) {
123-
return reject(new Error(`${uri}: ${response.statusCode || "500"}`))
124-
}
125-
126125
resolve(response)
127126
})
128127
client.on("error", reject)

0 commit comments

Comments
 (0)