Only retry on 401 once
This commit is contained in:
parent
d923c20aa6
commit
687447cea4
|
@ -23,7 +23,7 @@ proc genParams*(pars: openArray[(string, string)] = @[]; cursor="";
|
||||||
result &= ("count", count)
|
result &= ("count", count)
|
||||||
if cursor.len > 0:
|
if cursor.len > 0:
|
||||||
# The raw cursor often has plus signs, which sometimes get turned into spaces,
|
# The raw cursor often has plus signs, which sometimes get turned into spaces,
|
||||||
# so we need to them back into a plus
|
# so we need to turn them back into a plus
|
||||||
if " " in cursor:
|
if " " in cursor:
|
||||||
result &= ("cursor", cursor.replace(" ", "+"))
|
result &= ("cursor", cursor.replace(" ", "+"))
|
||||||
else:
|
else:
|
||||||
|
@ -69,9 +69,7 @@ template fetchImpl(result, fetchBody) {.dirty.} =
|
||||||
|
|
||||||
# Twitter randomly returns 401 errors with an empty body quite often.
|
# Twitter randomly returns 401 errors with an empty body quite often.
|
||||||
# Retrying the request usually works.
|
# Retrying the request usually works.
|
||||||
var attempt = 0
|
if resp.status == "401 Unauthorized" and result.len == 0:
|
||||||
while resp.status == "401 Unauthorized" and result.len == 0 and attempt < 3:
|
|
||||||
inc attempt
|
|
||||||
getContent()
|
getContent()
|
||||||
|
|
||||||
if resp.status == $Http503:
|
if resp.status == $Http503:
|
||||||
|
|
Loading…
Reference in New Issue