Procházet zdrojové kódy

Catch failed guest token exception

Zed před 6 roky
rodič
revize
0924ea033d
2 změnil soubory, kde provedl 8 přidání a 2 odebrání
  1. 5 1
      src/api/media.nim
  2. 3 1
      src/routes/media.nim

+ 5 - 1
src/api/media.nim

@@ -57,7 +57,11 @@ proc getGuestToken(agent: string; force=false): Future[string] {.async.} =
   let headers = genHeaders({"authorization": auth}, agent, base, lang=false)
   newClient()
 
-  let json = parseJson(await client.postContent($(apiBase / tokenUrl)))
+  var res: string
+  try: res = await client.postContent($(apiBase / tokenUrl))
+  except: return
+
+  let json = parseJson(res)
 
   if json != nil:
     result = json["guest_token"].to(string)

+ 3 - 1
src/routes/media.nim

@@ -31,10 +31,12 @@ proc createMediaRouter*(cfg: Config) =
         let client = newAsyncHttpClient()
         try:
           await client.downloadFile($uri, filename)
-          client.safeClose()
         except HttpRequestError:
+          client.safeClose()
           removeFile(filename)
           resp Http404
+        finally:
+          client.safeClose()
 
       sendFile(filename)