From 6bcbe0ea9f13a6063d8d247e26435da152cf81a5 Mon Sep 17 00:00:00 2001 From: Zed Date: Tue, 28 Dec 2021 05:02:28 +0100 Subject: [PATCH] Handle decompression errors --- src/apiutils.nim | 3 +++ src/nitter.nim | 11 ++++++++--- src/types.nim | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/apiutils.nim b/src/apiutils.nim index 552c984..c375000 100644 --- a/src/apiutils.nim +++ b/src/apiutils.nim @@ -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: diff --git a/src/nitter.nim b/src/nitter.nim index b281652..08d7c2b 100644 --- a/src/nitter.nim +++ b/src/nitter.nim @@ -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.
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.
Use {link} or try again later.", cfg) extend unsupported, "" extend preferences, "" diff --git a/src/types.nim b/src/types.nim index 7289cf3..8d8355d 100644 --- a/src/types.nim +++ b/src/types.nim @@ -6,6 +6,7 @@ genPrefsType() type RateLimitError* = object of CatchableError + InternalError* = object of CatchableError Token* = ref object tok*: string