mirror of
https://github.com/zedeus/nitter.git
synced 2024-12-12 02:56:29 +00:00
Catch SSL shutdown errors when closing clients
This commit is contained in:
parent
b09798f2cf
commit
ee43d8cfb1
3 changed files with 11 additions and 3 deletions
|
@ -26,7 +26,9 @@ proc genHeaders*(agent: string; referer: Uri; lang=true;
|
|||
|
||||
template newClient*() {.dirty.} =
|
||||
var client = newAsyncHttpClient()
|
||||
defer: client.close()
|
||||
defer:
|
||||
try: client.close()
|
||||
except: discard
|
||||
client.headers = headers
|
||||
|
||||
proc fetchHtml*(url: Uri; headers: HttpHeaders; jsonKey = ""): Future[XmlNode] {.async.} =
|
||||
|
|
|
@ -31,7 +31,7 @@ proc createMediaRouter*(cfg: Config) =
|
|||
let client = newAsyncHttpClient()
|
||||
try:
|
||||
await client.downloadFile($uri, filename)
|
||||
client.close()
|
||||
client.safeClose()
|
||||
except HttpRequestError:
|
||||
removeFile(filename)
|
||||
resp Http404
|
||||
|
|
|
@ -2,6 +2,8 @@ import strutils, sequtils, asyncdispatch, httpclient
|
|||
import ../utils, ../prefs
|
||||
export utils, prefs
|
||||
|
||||
from net import SslError
|
||||
|
||||
template cookiePrefs*(): untyped {.dirty.} =
|
||||
getPrefs(request.cookies.getOrDefault("preferences"), cfg)
|
||||
|
||||
|
@ -14,8 +16,12 @@ template refPath*(): untyped {.dirty.} =
|
|||
proc getNames*(name: string): seq[string] =
|
||||
name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
|
||||
|
||||
proc safeClose*(client: AsyncHttpClient) =
|
||||
try: client.close()
|
||||
except SslError: discard
|
||||
|
||||
proc safeFetch*(url: string): Future[string] {.async.} =
|
||||
let client = newAsyncHttpClient()
|
||||
try: result = await client.getContent(url)
|
||||
except: discard
|
||||
client.close()
|
||||
client.safeClose()
|
||||
|
|
Loading…
Reference in a new issue