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 end
opts[:logger].debug("Fetching #{url}") opts[:logger].debug("Fetching #{url}")
response = Request.run(url, { headers: headers }) response = Request.run(url, { connecttimeout: 15, headers: headers })
if response.success? if response.success?
response.body response.body
else else
opts[:logger].error("Couldn't fetch #{url} (response code #{response.code})") reason = response.timed_out? ? "Timed out while fetching #{url}" : "Couldn't fetch #{url} (response code #{response.code})"
nil opts[:logger].error(reason)
raise reason
end end
end end

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

Loading…
Cancel
Save