Fix crash on token fetch failure
This commit is contained in:
parent
7acea6b9e0
commit
3dc85639f4
|
@ -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"
|
"user-agent": "Mozilla/5.0 (X11; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0"
|
||||||
})
|
})
|
||||||
client = newAsyncHttpClient(headers=headers)
|
client = newAsyncHttpClient(headers=headers)
|
||||||
|
|
||||||
|
var resp: string
|
||||||
|
|
||||||
|
try:
|
||||||
resp = await client.getContent("https://twitter.com")
|
resp = await client.getContent("https://twitter.com")
|
||||||
pos = resp.rfind("gt=")
|
client.close()
|
||||||
|
except:
|
||||||
try: client.close()
|
echo "fetching token failed"
|
||||||
except: discard
|
return Token()
|
||||||
|
|
||||||
|
let pos = resp.rfind("gt=")
|
||||||
if pos == -1:
|
if pos == -1:
|
||||||
echo "token parse fail"
|
echo "token parse fail"
|
||||||
return Token()
|
return Token()
|
||||||
|
|
Loading…
Reference in New Issue