mirror of
https://github.com/zedeus/nitter.git
synced 2025-03-04 10:01:24 +00:00
Raise NoAccountsError when all accounts limited
This commit is contained in:
parent
19569bb19f
commit
28d3ed7d9f
3 changed files with 10 additions and 1 deletions
|
@ -125,6 +125,9 @@ proc getAccountPoolDebug*(): JsonNode =
|
||||||
proc rateLimitError*(): ref RateLimitError =
|
proc rateLimitError*(): ref RateLimitError =
|
||||||
newException(RateLimitError, "rate limited")
|
newException(RateLimitError, "rate limited")
|
||||||
|
|
||||||
|
proc noAccountsError*(): ref NoAccountsError =
|
||||||
|
newException(NoAccountsError, "no accounts available")
|
||||||
|
|
||||||
proc isLimited(account: GuestAccount; api: Api): bool =
|
proc isLimited(account: GuestAccount; api: Api): bool =
|
||||||
if account.isNil:
|
if account.isNil:
|
||||||
return true
|
return true
|
||||||
|
@ -165,7 +168,7 @@ proc getGuestAccount*(api: Api): Future[GuestAccount] {.async.} =
|
||||||
inc result.pending
|
inc result.pending
|
||||||
else:
|
else:
|
||||||
log "no accounts available for API: ", api
|
log "no accounts available for API: ", api
|
||||||
raise rateLimitError()
|
raise noAccountsError()
|
||||||
|
|
||||||
proc setLimited*(account: GuestAccount; api: Api) =
|
proc setLimited*(account: GuestAccount; api: Api) =
|
||||||
account.apis[api].limited = true
|
account.apis[api].limited = true
|
||||||
|
|
|
@ -97,6 +97,11 @@ routes:
|
||||||
resp Http429, showError(
|
resp Http429, showError(
|
||||||
&"Instance has been rate limited.<br>Use {link} or try again later.", cfg)
|
&"Instance has been rate limited.<br>Use {link} or try again later.", cfg)
|
||||||
|
|
||||||
|
error NoAccountsError:
|
||||||
|
const link = a("another instance", href = instancesUrl)
|
||||||
|
resp Http429, showError(
|
||||||
|
&"Instance has no available accounts.<br>Use {link} or try again later.", cfg)
|
||||||
|
|
||||||
extend rss, ""
|
extend rss, ""
|
||||||
extend status, ""
|
extend status, ""
|
||||||
extend search, ""
|
extend search, ""
|
||||||
|
|
|
@ -6,6 +6,7 @@ genPrefsType()
|
||||||
|
|
||||||
type
|
type
|
||||||
RateLimitError* = object of CatchableError
|
RateLimitError* = object of CatchableError
|
||||||
|
NoAccountsError* = object of CatchableError
|
||||||
InternalError* = object of CatchableError
|
InternalError* = object of CatchableError
|
||||||
BadClientError* = object of CatchableError
|
BadClientError* = object of CatchableError
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue