Misc: Unify error logging on network errors (#9523)

Making sure we get the relevant information in the logs, and that the UI feedback (if any), is meaningful and readable.
This commit is contained in:
NiLuJe
2022-09-17 00:08:00 +02:00
committed by GitHub
parent 6cb352bc03
commit 83a2965d6b
11 changed files with 71 additions and 53 deletions

View File

@@ -1104,14 +1104,16 @@ function ReaderDictionary:downloadDictionary(dict, download_location, continue)
end
socketutil:set_timeout(socketutil.FILE_BLOCK_TIMEOUT, socketutil.FILE_TOTAL_TIMEOUT)
local c = socket.skip(1, http.request{
local code, headers, status = socket.skip(1, http.request{
url = dict.url,
sink = ltn12.sink.file(io.open(download_location, "w")),
})
socketutil:reset_timeout()
if c == 200 then
if code == 200 then
logger.dbg("file downloaded to", download_location)
else
logger.dbg("ReaderDictionary: Request failed:", status or code)
logger.dbg("ReaderDictionary: Response headers:", headers)
UIManager:show(InfoMessage:new{
text = _("Could not save file to:\n") .. BD.filepath(download_location),
--timeout = 3,