瀏覽代碼

Fix crash when TID pair fetch fails

Zed 2 月之前
父節點
當前提交
0375145ea2
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      src/tid.nim

+ 4 - 2
src/tid.nim

@@ -16,14 +16,16 @@ var
 
 proc getPair(): Future[TidPair] {.async.} =
   if cachedPairs.len == 0 or int(epochTime()) - lastCached > ttlSec:
-    lastCached = int(epochTime())
-
     let client = newAsyncHttpClient()
     defer: client.close()
 
     let resp = await client.get(pairsUrl)
     if resp.status == $Http200:
       cachedPairs = parseTidPairs(await resp.body)
+      lastCached = int(epochTime())
+
+  if cachedPairs.len == 0:
+    raise newException(ValueError, "Failed to fetch x-client-transaction-id pairs")
 
   return sample(cachedPairs)