Fix http pool usage to prevent rate limit error
This commit is contained in:
parent
e183a9c789
commit
df9f90f99c
1 changed files with 5 additions and 4 deletions
|
@ -41,9 +41,10 @@ proc fetch*(url: Uri; oldApi=false): Future[JsonNode] {.async.} =
|
||||||
|
|
||||||
let headers = genHeaders(token)
|
let headers = genHeaders(token)
|
||||||
try:
|
try:
|
||||||
let
|
var resp: AsyncResponse
|
||||||
resp = pool.use(headers): await c.get($url)
|
let body = pool.use(headers):
|
||||||
body = await resp.body
|
resp = await c.get($url)
|
||||||
|
await resp.body
|
||||||
|
|
||||||
if body.startsWith('{') or body.startsWith('['):
|
if body.startsWith('{') or body.startsWith('['):
|
||||||
result = parseJson(body)
|
result = parseJson(body)
|
||||||
|
@ -65,6 +66,6 @@ proc fetch*(url: Uri; oldApi=false): Future[JsonNode] {.async.} =
|
||||||
raise rateLimitError()
|
raise rateLimitError()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
echo "error: ", e.msg, ", token: ", token[], ", url: ", url
|
echo "error: ", e.msg, ", token: ", token[], ", url: ", url
|
||||||
if "length" notin e.msg:
|
if "length" notin e.msg and "descriptor" notin e.msg:
|
||||||
release(token, true)
|
release(token, true)
|
||||||
raise rateLimitError()
|
raise rateLimitError()
|
||||||
|
|
Loading…
Reference in a new issue