Kaynağa Gözat

Handle decompression errors

Zed 4 yıl önce
ebeveyn
işleme
6bcbe0ea9f
3 değiştirilmiş dosya ile 12 ekleme ve 3 silme
  1. 3 0
      src/apiutils.nim
  2. 8 3
      src/nitter.nim
  3. 1 0
      src/types.nim

+ 3 - 0
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:

+ 8 - 3
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.<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, ""

+ 1 - 0
src/types.nim

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