Add user agent for media requests, improve error

This commit is contained in:
Zed
2020-06-02 20:27:43 +02:00
parent 9b34123573
commit 7acea6b9e0
2 changed files with 18 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
import strutils, sequtils, asyncdispatch, httpclient, uri
from jester import Request
import ../utils, ../prefs
import ".."/[utils, prefs]
export utils, prefs
template savePref*(pref, value: string; req: Request; expire=false) =
@@ -33,8 +33,8 @@ proc safeClose*(client: AsyncHttpClient) =
try: client.close()
except: discard
proc safeFetch*(url: string): Future[string] {.async.} =
let client = newAsyncHttpClient()
proc safeFetch*(url, agent: string): Future[string] {.async.} =
let client = newAsyncHttpClient(userAgent=agent)
try: result = await client.getContent(url)
except: discard
finally: client.safeClose()