mirror of
https://github.com/zedeus/nitter.git
synced 2025-12-06 03:55:36 -05:00
Stop logging unimportant errors
This commit is contained in:
@@ -7,6 +7,7 @@ import experimental/types/common
|
|||||||
const
|
const
|
||||||
rlRemaining = "x-rate-limit-remaining"
|
rlRemaining = "x-rate-limit-remaining"
|
||||||
rlReset = "x-rate-limit-reset"
|
rlReset = "x-rate-limit-reset"
|
||||||
|
errorsToSkip = {doesntExist, tweetNotFound, timeout, unauthorized, badRequest}
|
||||||
|
|
||||||
var pool: HttpPool
|
var pool: HttpPool
|
||||||
|
|
||||||
@@ -76,14 +77,15 @@ template fetchImpl(result, fetchBody) {.dirty.} =
|
|||||||
|
|
||||||
if result.startsWith("{\"errors"):
|
if result.startsWith("{\"errors"):
|
||||||
let errors = result.fromJson(Errors)
|
let errors = result.fromJson(Errors)
|
||||||
echo "Fetch error, API: ", api, ", errors: ", errors
|
if errors notin errorsToSkip:
|
||||||
if errors in {expiredToken, badToken, locked}:
|
echo "Fetch error, API: ", api, ", errors: ", errors
|
||||||
invalidate(session)
|
if errors in {expiredToken, badToken, locked}:
|
||||||
raise rateLimitError()
|
invalidate(session)
|
||||||
elif errors in {rateLimited}:
|
raise rateLimitError()
|
||||||
# rate limit hit, resets after 24 hours
|
elif errors in {rateLimited}:
|
||||||
setLimited(session, api)
|
# rate limit hit, resets after 24 hours
|
||||||
raise rateLimitError()
|
setLimited(session, api)
|
||||||
|
raise rateLimitError()
|
||||||
elif result.startsWith("429 Too Many Requests"):
|
elif result.startsWith("429 Too Many Requests"):
|
||||||
echo "[sessions] 429 error, API: ", api, ", session: ", session.id
|
echo "[sessions] 429 error, API: ", api, ", session: ", session.id
|
||||||
session.apis[api].remaining = 0
|
session.apis[api].remaining = 0
|
||||||
@@ -126,7 +128,7 @@ proc fetch*(url: Uri; api: Api): Future[JsonNode] {.async.} =
|
|||||||
result = newJNull()
|
result = newJNull()
|
||||||
|
|
||||||
let error = result.getError
|
let error = result.getError
|
||||||
if error != null:
|
if error != null and error notin errorsToSkip:
|
||||||
echo "Fetch error, API: ", api, ", error: ", error
|
echo "Fetch error, API: ", api, ", error: ", error
|
||||||
if error in {expiredToken, badToken, locked}:
|
if error in {expiredToken, badToken, locked}:
|
||||||
invalidate(session)
|
invalidate(session)
|
||||||
|
|||||||
@@ -45,8 +45,10 @@ type
|
|||||||
noUserMatches = 17
|
noUserMatches = 17
|
||||||
protectedUser = 22
|
protectedUser = 22
|
||||||
missingParams = 25
|
missingParams = 25
|
||||||
|
timeout = 29
|
||||||
couldntAuth = 32
|
couldntAuth = 32
|
||||||
doesntExist = 34
|
doesntExist = 34
|
||||||
|
unauthorized = 37
|
||||||
invalidParam = 47
|
invalidParam = 47
|
||||||
userNotFound = 50
|
userNotFound = 50
|
||||||
suspended = 63
|
suspended = 63
|
||||||
@@ -56,6 +58,7 @@ type
|
|||||||
tweetNotFound = 144
|
tweetNotFound = 144
|
||||||
tweetNotAuthorized = 179
|
tweetNotAuthorized = 179
|
||||||
forbidden = 200
|
forbidden = 200
|
||||||
|
badRequest = 214
|
||||||
badToken = 239
|
badToken = 239
|
||||||
locked = 326
|
locked = 326
|
||||||
noCsrf = 353
|
noCsrf = 353
|
||||||
|
|||||||
Reference in New Issue
Block a user