aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Bünemann2016-01-28 05:51:25 +0100
committerMike McQuaid2016-02-01 18:37:36 +0000
commitf32c2a99740617140a019f1309113e2669684beb (patch)
tree740f1244a32afc13c774bf4db8f5edfec9f08435
parenta584711115ef2c7aa4254f6b88975ed6977c9d3a (diff)
downloadbrew-f32c2a99740617140a019f1309113e2669684beb.tar.bz2
brew search: properly handle 503 errors.
This avoids crashing with an unknown key error, if the GitHub api response does not contain the ratelimit headers, e.g. when GitHub is down. It also tries to display the JSON error message in addition to the HTTP status. Closes Homebrew/homebrew#48538. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
-rw-r--r--Library/Homebrew/utils.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index d9a41b86d..e020caef0 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -531,7 +531,7 @@ module GitHub
end
def handle_api_error(e)
- if e.io.meta["x-ratelimit-remaining"].to_i <= 0
+ if e.io.meta.fetch("x-ratelimit-remaining", 1).to_i <= 0
reset = e.io.meta.fetch("x-ratelimit-reset").to_i
error = Utils::JSON.load(e.io.read)["message"]
raise RateLimitExceededError.new(reset, error)
@@ -543,7 +543,8 @@ module GitHub
when "404"
raise HTTPNotFoundError, e.message, e.backtrace
else
- raise Error, e.message, e.backtrace
+ error = Utils::JSON.load(e.io.read)["message"] rescue nil
+ raise Error, [e.message, error].compact.join("\n"), e.backtrace
end
end