mirror of
https://github.com/zedeus/nitter.git
synced 2024-12-13 11:36:34 +00:00
Retry intermittent 401 Unauthorized requests
This commit is contained in:
parent
1cf8e67567
commit
2ac3afa5b2
1 changed files with 15 additions and 5 deletions
|
@ -61,9 +61,19 @@ template fetchImpl(result, fetchBody) {.dirty.} =
|
||||||
try:
|
try:
|
||||||
var resp: AsyncResponse
|
var resp: AsyncResponse
|
||||||
pool.use(genHeaders(token)):
|
pool.use(genHeaders(token)):
|
||||||
|
template getContent =
|
||||||
resp = await c.get($url)
|
resp = await c.get($url)
|
||||||
result = await resp.body
|
result = await resp.body
|
||||||
|
|
||||||
|
getContent()
|
||||||
|
|
||||||
|
# Twitter randomly returns 401 errors with an empty body quite often.
|
||||||
|
# Retrying the request usually works.
|
||||||
|
var attempt = 0
|
||||||
|
while resp.status == "401 Unauthorized" and result.len == 0 and attempt < 3:
|
||||||
|
inc attempt
|
||||||
|
getContent()
|
||||||
|
|
||||||
if resp.status == $Http503:
|
if resp.status == $Http503:
|
||||||
badClient = true
|
badClient = true
|
||||||
raise newException(InternalError, result)
|
raise newException(InternalError, result)
|
||||||
|
|
Loading…
Reference in a new issue