Skip to content
Snippets Groups Projects
Commit f32c2a99 authored by Felix Bünemann's avatar Felix Bünemann Committed by Mike McQuaid
Browse files

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: default avatarMike McQuaid <mike@mikemcquaid.com>
parent a5847111
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment