Catch SSL shutdown errors when closing clients
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user