Catch more httpclient exceptions

This commit is contained in:
Zed 2020-03-09 00:17:13 +01:00
parent 9608876783
commit 211cd5964a
1 changed files with 2 additions and 4 deletions

View File

@ -2,8 +2,6 @@ import strutils, sequtils, asyncdispatch, httpclient
import ../utils, ../prefs import ../utils, ../prefs
export utils, prefs export utils, prefs
from net import SslError
template cookiePrefs*(): untyped {.dirty.} = template cookiePrefs*(): untyped {.dirty.} =
getPrefs(request.cookies.getOrDefault("preferences"), cfg) getPrefs(request.cookies.getOrDefault("preferences"), cfg)
@ -18,10 +16,10 @@ proc getNames*(name: string): seq[string] =
proc safeClose*(client: AsyncHttpClient) = proc safeClose*(client: AsyncHttpClient) =
try: client.close() try: client.close()
except SslError: discard except: discard
proc safeFetch*(url: string): Future[string] {.async.} = proc safeFetch*(url: string): Future[string] {.async.} =
let client = newAsyncHttpClient() let client = newAsyncHttpClient()
try: result = await client.getContent(url) try: result = await client.getContent(url)
except: discard except: discard
client.safeClose() finally: client.safeClose()