From df9f90f99ca5224abadf65599222cf6fa8dbd403 Mon Sep 17 00:00:00 2001 From: Zed Date: Sun, 18 Jul 2021 03:36:27 +0200 Subject: [PATCH] Fix http pool usage to prevent rate limit error --- src/apiutils.nim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/apiutils.nim b/src/apiutils.nim index e44769b..2a1e42e 100644 --- a/src/apiutils.nim +++ b/src/apiutils.nim @@ -41,9 +41,10 @@ proc fetch*(url: Uri; oldApi=false): Future[JsonNode] {.async.} = let headers = genHeaders(token) try: - let - resp = pool.use(headers): await c.get($url) - body = await resp.body + var resp: AsyncResponse + let body = pool.use(headers): + resp = await c.get($url) + await resp.body if body.startsWith('{') or body.startsWith('['): result = parseJson(body) @@ -65,6 +66,6 @@ proc fetch*(url: Uri; oldApi=false): Future[JsonNode] {.async.} = raise rateLimitError() except Exception as e: 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) raise rateLimitError()