Simplify bad http client pruning

This commit is contained in:
Zed
2022-01-23 02:29:03 +01:00
parent dcfdd225a2
commit 79b98a8081
2 changed files with 14 additions and 15 deletions

View File

@@ -58,17 +58,15 @@ template fetchImpl(result, fetchBody) {.dirty.} =
if token.tok.len == 0:
raise rateLimitError()
var
client = pool.acquire(genHeaders(token))
badClient = false
try:
let resp = await client.get($url)
result = await resp.body
var resp: AsyncResponse
pool.use(genHeaders(token)):
resp = await c.get(url)
result = await resp.body
if resp.status == $Http503:
badClient = true
raise newException(InternalError, result)
if resp.status == $Http503:
badClient = true
raise newException(InternalError, result)
if result.len > 0:
if resp.headers.getOrDefault("content-encoding") == "gzip":
@@ -89,8 +87,6 @@ template fetchImpl(result, fetchBody) {.dirty.} =
if "length" notin e.msg and "descriptor" notin e.msg:
release(token, invalid=true)
raise rateLimitError()
finally:
pool.release(client, badClient=badClient)
proc fetch*(url: Uri; api: Api): Future[JsonNode] {.async.} =
var body: string