Handle decompression errors

This commit is contained in:
Zed 2021-12-28 05:02:28 +01:00
parent 4b356118a6
commit 6bcbe0ea9f
3 changed files with 12 additions and 3 deletions

View file

@ -64,6 +64,9 @@ proc fetch*(url: Uri; oldApi=false): Future[JsonNode] {.async.} =
echo "fetch error: ", result.getError
release(token, true)
raise rateLimitError()
except ZippyError as e:
echo "decompression error: ", e.msg, ", url: ", url
raise newException(InternalError, "decompression failed: " & $url)
except Exception as e:
echo "error: ", e.msg, ", token: ", token[], ", url: ", url
if "length" notin e.msg and "descriptor" notin e.msg:

View file

@ -13,6 +13,7 @@ import routes/[
unsupported, embed, resolver, router_utils]
const instancesUrl = "https://github.com/zedeus/nitter/wiki/Instances"
const issuesUrl = "https://github.com/zedeus/nitter/issues"
let configPath = getEnv("NITTER_CONF_FILE", "./nitter.conf")
let (cfg, fullCfg) = getConfig(configPath)
@ -75,11 +76,15 @@ routes:
error Http404:
resp Http404, showError("Page not found", cfg)
error InternalError:
echo error.exc.msg
const link = a("open a GitHub issue", href = issuesUrl)
resp Http500, showError(&"An error occurred, please {link} with the URL you tried to visit.", cfg)
error RateLimitError:
echo error.exc.msg
resp Http429, showError("Instance has been rate limited.<br>Use " &
a("another instance", href = instancesUrl) &
" or try again later.", cfg)
const link = a("another instance", href = instancesUrl)
resp Http429, showError(&"Instance has been rate limited.<br>Use {link} or try again later.", cfg)
extend unsupported, ""
extend preferences, ""

View file

@ -6,6 +6,7 @@ genPrefsType()
type
RateLimitError* = object of CatchableError
InternalError* = object of CatchableError
Token* = ref object
tok*: string