Skip to content
Snippets Groups Projects
Commit ea741523 authored by Jack Nagel's avatar Jack Nagel
Browse files

Add helpful error message for authentication failures

parent 3cbb4993
No related branches found
No related tags found
No related merge requests found
......@@ -253,7 +253,6 @@ module GitHub extend self
Error = Class.new(RuntimeError)
HTTPNotFoundError = Class.new(Error)
AuthenticationFailedError = Class.new(Error)
class RateLimitExceededError < Error
def initialize(reset, error)
......@@ -274,6 +273,16 @@ module GitHub extend self
end
end
class AuthenticationFailedError < Error
def initialize(error)
super <<-EOS.undent
GitHub #{error}
HOMEBREW_GITHUB_API_TOKEN may be invalid or expired, check:
https://github.com/settings/applications
EOS
end
end
def open url, headers={}, &block
# This is a no-op if the user is opting out of using the GitHub API.
return if ENV['HOMEBREW_NO_GITHUB_API']
......@@ -306,7 +315,7 @@ module GitHub extend self
case e.io.status.first
when "401", "403"
raise AuthenticationFailedError, e.message, e.backtrace
raise AuthenticationFailedError.new(e.message)
when "404"
raise HTTPNotFoundError, e.message, e.backtrace
else
......
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