diff --git a/src/apiutils.nim b/src/apiutils.nim index 3a0d12c..65dcc29 100644 --- a/src/apiutils.nim +++ b/src/apiutils.nim @@ -7,6 +7,7 @@ import experimental/types/common const rlRemaining = "x-rate-limit-remaining" rlReset = "x-rate-limit-reset" + errorsToSkip = {doesntExist, tweetNotFound, timeout, unauthorized, badRequest} var pool: HttpPool @@ -76,14 +77,15 @@ template fetchImpl(result, fetchBody) {.dirty.} = if result.startsWith("{\"errors"): let errors = result.fromJson(Errors) - echo "Fetch error, API: ", api, ", errors: ", errors - if errors in {expiredToken, badToken, locked}: - invalidate(session) - raise rateLimitError() - elif errors in {rateLimited}: - # rate limit hit, resets after 24 hours - setLimited(session, api) - raise rateLimitError() + if errors notin errorsToSkip: + echo "Fetch error, API: ", api, ", errors: ", errors + if errors in {expiredToken, badToken, locked}: + invalidate(session) + raise rateLimitError() + elif errors in {rateLimited}: + # rate limit hit, resets after 24 hours + setLimited(session, api) + raise rateLimitError() elif result.startsWith("429 Too Many Requests"): echo "[sessions] 429 error, API: ", api, ", session: ", session.id session.apis[api].remaining = 0 @@ -126,7 +128,7 @@ proc fetch*(url: Uri; api: Api): Future[JsonNode] {.async.} = result = newJNull() let error = result.getError - if error != null: + if error != null and error notin errorsToSkip: echo "Fetch error, API: ", api, ", error: ", error if error in {expiredToken, badToken, locked}: invalidate(session) diff --git a/src/types.nim b/src/types.nim index 6c1f1b6..4e565ee 100644 --- a/src/types.nim +++ b/src/types.nim @@ -45,8 +45,10 @@ type noUserMatches = 17 protectedUser = 22 missingParams = 25 + timeout = 29 couldntAuth = 32 doesntExist = 34 + unauthorized = 37 invalidParam = 47 userNotFound = 50 suspended = 63 @@ -56,6 +58,7 @@ type tweetNotFound = 144 tweetNotAuthorized = 179 forbidden = 200 + badRequest = 214 badToken = 239 locked = 326 noCsrf = 353