i tried my hardest to ratelimit myself locally and it didnt work so this code fixes ratelimit issues :)

This commit is contained in:
Cynthia Foxwell 2025-02-11 13:15:17 -07:00
parent c9b2e94ba9
commit be4c83bfb0
Signed by: Cynosphere
SSH key fingerprint: SHA256:H3SM8ufP/uxqLwKSH7xY89TDnbR9uOHzjLoBr0tlajk

View file

@ -125,7 +125,7 @@ template fetchImpl(result, additional_headers, fetchBody) {.dirty.} =
except OSError as e:
raise e
except Exception as e:
#echo "error: ", e.name, ", msg: ", e.msg, ", token: ", token[], ", url: ", url
echo "error: ", e.name, ", msg: ", e.msg, ", url: ", url
#if "length" notin e.msg and "descriptor" notin e.msg:
#release(token, invalid=true)
raise rateLimitError()
@ -138,7 +138,7 @@ template retry(bod) =
bod
proc fetch*(url: Uri; api: Api; additional_headers: HttpHeaders = newHttpHeaders()): Future[JsonNode] {.async.} =
retry:
#retry:
var body: string
fetchImpl(body, additional_headers):
if body.startsWith('{') or body.startsWith('['):
@ -156,7 +156,7 @@ proc fetch*(url: Uri; api: Api; additional_headers: HttpHeaders = newHttpHeaders
raise rateLimitError()
proc fetchRaw*(url: Uri; api: Api; additional_headers: HttpHeaders = newHttpHeaders()): Future[string] {.async.} =
retry:
#retry:
fetchImpl(result, additional_headers):
if not (result.startsWith('{') or result.startsWith('[')):
echo resp.status, ": ", result, " --- url: ", url