From 3dc85639f4d97aeffa360c9e803ad4ac87f59bc2 Mon Sep 17 00:00:00 2001 From: Zed Date: Tue, 2 Jun 2020 20:37:55 +0200 Subject: [PATCH] Fix crash on token fetch failure --- src/tokens.nim | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/tokens.nim b/src/tokens.nim index 078ff5d..7212350 100644 --- a/src/tokens.nim +++ b/src/tokens.nim @@ -12,12 +12,17 @@ proc fetchToken(): Future[Token] {.async.} = "user-agent": "Mozilla/5.0 (X11; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0" }) client = newAsyncHttpClient(headers=headers) + + var resp: string + + try: resp = await client.getContent("https://twitter.com") - pos = resp.rfind("gt=") - - try: client.close() - except: discard + client.close() + except: + echo "fetching token failed" + return Token() + let pos = resp.rfind("gt=") if pos == -1: echo "token parse fail" return Token()