From 28d3ed7d9fad2302bf357f099c8b8951631dee8c Mon Sep 17 00:00:00 2001 From: Zed Date: Wed, 5 Feb 2025 00:32:55 +0100 Subject: [PATCH] Raise NoAccountsError when all accounts limited --- src/auth.nim | 5 ++++- src/nitter.nim | 5 +++++ src/types.nim | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/auth.nim b/src/auth.nim index a15766b..20e136f 100644 --- a/src/auth.nim +++ b/src/auth.nim @@ -125,6 +125,9 @@ proc getAccountPoolDebug*(): JsonNode = proc rateLimitError*(): ref RateLimitError = newException(RateLimitError, "rate limited") +proc noAccountsError*(): ref NoAccountsError = + newException(NoAccountsError, "no accounts available") + proc isLimited(account: GuestAccount; api: Api): bool = if account.isNil: return true @@ -165,7 +168,7 @@ proc getGuestAccount*(api: Api): Future[GuestAccount] {.async.} = inc result.pending else: log "no accounts available for API: ", api - raise rateLimitError() + raise noAccountsError() proc setLimited*(account: GuestAccount; api: Api) = account.apis[api].limited = true diff --git a/src/nitter.nim b/src/nitter.nim index dfc1dfd..958dc0b 100644 --- a/src/nitter.nim +++ b/src/nitter.nim @@ -97,6 +97,11 @@ routes: resp Http429, showError( &"Instance has been rate limited.
Use {link} or try again later.", cfg) + error NoAccountsError: + const link = a("another instance", href = instancesUrl) + resp Http429, showError( + &"Instance has no available accounts.
Use {link} or try again later.", cfg) + extend rss, "" extend status, "" extend search, "" diff --git a/src/types.nim b/src/types.nim index 1b9189b..d1981d7 100644 --- a/src/types.nim +++ b/src/types.nim @@ -6,6 +6,7 @@ genPrefsType() type RateLimitError* = object of CatchableError + NoAccountsError* = object of CatchableError InternalError* = object of CatchableError BadClientError* = object of CatchableError