Skip to content

Commit

Permalink
Only retry on 401 once
Browse files Browse the repository at this point in the history
  • Loading branch information
zedeus committed Dec 19, 2022
1 parent d923c20 commit 687447c
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/apiutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ proc genParams*(pars: openArray[(string, string)] = @[]; cursor="";
result &= ("count", count)
if cursor.len > 0:
# 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:
result &= ("cursor", cursor.replace(" ", "+"))
else:
Expand Down Expand Up @@ -69,9 +69,7 @@ template fetchImpl(result, fetchBody) {.dirty.} =

# 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
if resp.status == "401 Unauthorized" and result.len == 0:
getContent()

if resp.status == $Http503:
Expand Down

0 comments on commit 687447c

Please sign in to comment.