Show error page when rate limited

This commit is contained in:
Zed
2021-01-07 22:31:29 +01:00
parent 2128b280b4
commit 4e1d213488
6 changed files with 25 additions and 5 deletions

View File

@@ -31,13 +31,16 @@ proc genHeaders*(token: Token = nil): HttpHeaders =
"DNT": "1"
})
proc rateLimitError(): ref RateLimitError =
newException(RateLimitError, "rate limited with " & getPoolInfo())
proc fetch*(url: Uri; oldApi=false): Future[JsonNode] {.async.} =
once:
pool = HttpPool()
var token = await getToken()
if token.tok.len == 0:
result = newJNull()
raise rateLimitError()
let headers = genHeaders(token)
try:
@@ -59,4 +62,4 @@ proc fetch*(url: Uri; oldApi=false): Future[JsonNode] {.async.} =
token.release()
except Exception:
echo "error: ", url
result = newJNull()
raise rateLimitError()