Better error handling and added a 15s timeout on HTTP requests

pull/986/head
Jasper van Merle 6 years ago
parent 1b35b21dd6
commit 11eeadbc0a

@ -223,13 +223,14 @@ module Docs
end
opts[:logger].debug("Fetching #{url}")
response = Request.run(url, { headers: headers })
response = Request.run(url, { connecttimeout: 15, headers: headers })
if response.success?
response.body
else
opts[:logger].error("Couldn't fetch #{url} (response code #{response.code})")
nil
reason = response.timed_out? ? "Timed out while fetching #{url}" : "Couldn't fetch #{url} (response code #{response.code})"
opts[:logger].error(reason)
raise reason
end
end

@ -72,9 +72,9 @@ class UpdatesCLI < Thor
rescue NotImplementedError
logger.warn("Couldn't check #{doc.name}, get_latest_version is not implemented")
error_result(doc, '`get_latest_version` is not implemented')
rescue
logger.error("Error while checking #{doc.name}")
raise
rescue => error
logger.error("Error while checking #{doc.name}\n#{error.full_message.strip}")
error_result(doc, error.message.gsub(/'/, '`'))
end
def format_version(version)

Loading…
Cancel
Save