utils/github: add ValidationFailedError.
These have specific errors returned so would be more useful to output.
This commit is contained in:
parent
473155e12c
commit
056dd588b2
@ -45,7 +45,7 @@ module GitHub
|
||||
class AuthenticationFailedError < Error
|
||||
def initialize(github_message)
|
||||
@github_message = github_message
|
||||
message = "GitHub #{github_message}\n"
|
||||
message = "GitHub #{github_message}:"
|
||||
if ENV["HOMEBREW_GITHUB_API_TOKEN"]
|
||||
message << <<~EOS
|
||||
HOMEBREW_GITHUB_API_TOKEN may be invalid or expired; check:
|
||||
@ -65,6 +65,18 @@ module GitHub
|
||||
end
|
||||
end
|
||||
|
||||
class ValidationFailedError < Error
|
||||
def initialize(github_message, errors)
|
||||
@github_message = if errors.empty?
|
||||
github_message
|
||||
else
|
||||
"#{github_message}: #{errors}"
|
||||
end
|
||||
|
||||
super(@github_message)
|
||||
end
|
||||
end
|
||||
|
||||
def api_credentials
|
||||
@api_credentials ||= begin
|
||||
if ENV["HOMEBREW_GITHUB_API_TOKEN"]
|
||||
@ -231,6 +243,9 @@ module GitHub
|
||||
raise AuthenticationFailedError, message
|
||||
when "404"
|
||||
raise HTTPNotFoundError, message
|
||||
when "422"
|
||||
errors = json&.[]("errors") || []
|
||||
raise ValidationFailedError.new(message, errors)
|
||||
else
|
||||
raise Error, message
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user