api: improve exception handling.

This commit is contained in:
Mike McQuaid 2023-02-04 13:22:15 +01:00
parent cbda171c2b
commit 9ba6aef820
No known key found for this signature in database
GPG Key ID: 3338A31AFDB1D829

View File

@ -45,15 +45,16 @@ module Homebrew
curl_args.prepend("--time-cond", target) if target.exist? && !target.empty?
begin
# Disable retries here, we handle them ourselves below.
Utils::Curl.curl_download(*curl_args, to: target, max_time: JSON_API_MAX_TIME, retries: 0)
begin
# Disable retries here, we handle them ourselves below.
Utils::Curl.curl_download(*curl_args, to: target, max_time: JSON_API_MAX_TIME, retries: 0)
rescue ErrorDuringExecution
raise unless target.exist?
raise if target.empty?
JSON.parse(target.read)
rescue ErrorDuringExecution
raise unless target.exist?
raise if target.empty?
opoo "#{target.basename}: update failed, falling back to cached version."
end
opoo "#{target.basename}: update failed, falling back to cached version."
JSON.parse(target.read)
rescue JSON::ParserError
target.unlink