mirror of
https://github.com/zedeus/nitter.git
synced 2024-12-14 03:56:29 +00:00
Retry rate limited requests with different account
This commit is contained in:
parent
4250245263
commit
fcd74e8048
1 changed files with 28 additions and 18 deletions
|
@ -120,12 +120,21 @@ template fetchImpl(result, fetchBody) {.dirty.} =
|
|||
except OSError as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
echo "error: ", e.name, ", msg: ", e.msg, ", accountId: ", account.id, ", url: ", url
|
||||
let id = if account.isNil: "null" else: account.id
|
||||
echo "error: ", e.name, ", msg: ", e.msg, ", accountId: ", id, ", url: ", url
|
||||
raise rateLimitError()
|
||||
finally:
|
||||
release(account)
|
||||
|
||||
template retry(bod) =
|
||||
try:
|
||||
bod
|
||||
except RateLimitError:
|
||||
echo "[accounts] Rate limited, retrying ", api, " request..."
|
||||
bod
|
||||
|
||||
proc fetch*(url: Uri; api: Api): Future[JsonNode] {.async.} =
|
||||
retry:
|
||||
var body: string
|
||||
fetchImpl body:
|
||||
if body.startsWith('{') or body.startsWith('['):
|
||||
|
@ -141,6 +150,7 @@ proc fetch*(url: Uri; api: Api): Future[JsonNode] {.async.} =
|
|||
raise rateLimitError()
|
||||
|
||||
proc fetchRaw*(url: Uri; api: Api): Future[string] {.async.} =
|
||||
retry:
|
||||
fetchImpl result:
|
||||
if not (result.startsWith('{') or result.startsWith('[')):
|
||||
echo resp.status, ": ", result, " --- url: ", url
|
||||
|
|
Loading…
Reference in a new issue