Add helpful error message for authentication failures
This commit is contained in:
parent
3cbb49930c
commit
ea7415237c
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user